2011-09-16 3 views
1

1000 요소가있는 UITableView가 있습니다. 처음으로로드하기 전에 Instruments는 2.20MB의 바이트가 여전히 살아 있음을 보여줍니다. 충전 후 4.82MB로 표시됩니다. 메모리를 해제하고 이전 상태로 돌아 가면 4.71MB를 표시합니다. 하지만 이제 동일한 테이블을로드하면 Instruments는 4.82MB를 다시 표시합니다. UITableView의 구조가 캐시에 저장되어 있습니까? 그렇다면이 메모리를 해제 할 수있는 방법이 있습니까?캐시 된 요소 UITableView

내 테이블 구조 : 물론

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"SearchResult"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; 
    } 

    if(!isSomeStateSearching) cell.textLabel.text = [[[contentSomeState objectAtIndex:indexPath.section] objectForKey:@"rowValues"] objectAtIndex:indexPath.row]; 
    else 
    { 
     cell.textLabel.text = [searchedAllContent objectAtIndex:indexPath.row]; 
    } 

    UIView *v = [[[UIView alloc] init] autorelease]; 
    v.backgroundColor = [UIColor colorWithRed:188/255.0 green:57/255.0 blue:25/255.0 alpha:1.0]; 
    cell.selectedBackgroundView = v; 

    UIImageView *arrow = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seta_navegacao"]] autorelease]; 
    cell.accessoryView = arrow; 

    return cell; 
} 

답변

0

당신이 바로, 제대로 UITableViewCell의 재사용 메커니즘을 사용할 수 있습니까?

+0

예, 질문에 추가하겠습니다. – flopes

0

새 셀을 초기화 할 때만 셀 하위 뷰를 할당하고 추가해야합니다. 셀을 다시 사용할 때마다 새로운보기 및 이미지보기를 생성합니다. 이것이 당신의 식탁이 너무 많은 기억을 차지하는 이유입니다.

+0

문제는 너무 많은 메모리를 사용하지 않습니다. 문제는 메모리가 결국 해제되지 않는다는 것입니다. 코드의 끝에서 뷰와 이미지 뷰를 주석 처리 할 수 ​​있으며 문제는 계속됩니다. – flopes