0

왜 ARC가 활성화 된 상태에서 메모리 누수가 발생합니까 (굵게 강조 표시)? ARC가 활성화 된 상태에서 사용자 정의 셀 메모리 누수가 발생했습니다.

나는 내있는 tableview의 conteroller에서
+(CustomCell*)cell 
{ 


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"CustomCell_iPhone" owner:self options:nil];   
     return [nib objectAtIndex:0]; 

    } else { 
     NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"CustomCell_iPad" owner:self options:nil];   **//leaking 100%** 
     return [nib objectAtIndex:0]; 

    } 
} 

CustomCell.m

있습니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell=[CustomCell cell]; **// 100% leaking** 
... 
} 

답변

1

그래서, 두 가지를. 하나, .xib 파일에서이 셀을 생성하는 중입니다. IB의 셀에 재사용 식별자를 설정하십시오. 이 같은 :, cellForRowAtIndexPath을 : 그럼, 대신 CustomCell 클래스의 방법을,있는 tableView에 펜촉을 언로드

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Assuming you set a reuse identifier "cellId" in the nib for your table view cell... 
    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:@"cellId"]; 
    if (!cell) { 
     // If you didn't get a valid cell reference back, unload a cell from the nib 
     NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:nil options:nil]; 
     for (id obj in nibArray) { 
      if ([obj isMemberOfClass:[MyCell class]]) { 
       // Assign cell to obj, and add a target action for the checkmark 
       cell = (MyCell *)obj; 
       break; 
      } 
     } 
    } 

    return cell; 
} 

두 번째 것은 먼저 재사용 가능한 셀을 큐에서 시도하여, 당신은 훨씬 더 나은 성능을 얻을 것입니다.

관련 문제