2011-05-16 75 views
0

我看到以下日誌...這段代碼爲什麼調用自動釋放池?

「__NSAutoreleaseNoPool():有沒有到位池自動釋放類UITableViewCellContentView的對象0x58264b0 - 剛剛泄露」

這是一個巨大的釋放池日誌,上面只是其中一個版本日誌,我複製...

我有一個CustomCell根據業務邏輯添加瓷磚本身。但問題是當我打電話創建單元格時,我看到上面的日誌消息。我沒有看到我的代碼有任何問題..有沒有人有任何線索?

- (UITableViewCell *) tableView:(UITableView *)inTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UnSavedNoteListCell *cell; 
    NSString *CellIdentifier = [@"Cell_" stringByAppendingString:[NSString stringWithFormat:@"%d", indexPath.row]]; 
    cell = (UnSavedNoteListCell *)[inTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


if (cell == nil) 
{ 

    NSMutableArray *cellProgressNoteCollection = [self getcellProgressNoteCollectionForLandScape:indexPath]; 
    cell = [[[UnSavedNoteListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier cellTiles:cellProgressNoteCollection] autorelease]; 
    cell.backgroundColor = [UIColor clearColor]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

} 

// cell.textLabel.text = [NSString stringWithFormat:@"%d", rand()]; 
// cell.textLabel.textColor = [UIColor redColor]; 
// Configure the cell... 

return cell; 
} 

回答

0

我注意到的一件事是,你沒有重複使用任何你的uitableviewcells,所以你可能會受到很大的性能影響。在上面的代碼中,您正在爲每一行創建一個新的單元標識符。試試這個:

- (UITableViewCell *) tableView:(UITableView *)inTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = @"Cell"; 
    UnSavedNoteListCell *cell = (UnSavedNoteListCell *)[inTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     NSMutableArray *cellProgressNoteCollection = [self getcellProgressNoteCollectionForLandScape:indexPath]; 
     cell = [[[UnSavedNoteListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier cellTiles:cellProgressNoteCollection] autorelease]; 
     cell.backgroundColor = [UIColor clearColor]; 
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

    } 

    return cell; 
} 

這樣,您的tableview可以維護標記爲重用的表格單元列表。

0

更好的問題是爲什麼你沒有自動釋放池。

以下是您在該代碼中可能需要使用自動釋放池的一些調用。 (有些人可能不這樣做,實際上):

  • stringByAppendingString
  • stringWithFormat
  • dequeueReusableCellWithIdentifier
  • autorelease
  • getcellProgressNoteCollectionForLandScape(如果它的每約定書面)
  • clearColor(理論上,但可能不是)

UIKit需要一個自動釋放池。

你,我看到兩個潛在原因:

  1. 你自動釋放池不見了。 (它去了哪裏?)
  2. 這是從主線程以外的線程調用的。