2012-10-25 40 views
2

朋友,器材顯示內存泄漏loadNibNamed

我我的代碼運行在儀器,它顯示內存泄漏在5號線(出下面的代碼),即cell = [[[NSBundle mainBundle] loadNibNamed:@"ZoomCustomVideoCell" owner:self options:nil] objectAtIndex:0];

我不知道爲什麼它顯示了內存泄漏有什麼是相同

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

    static NSString *CellIdentifier = @"ZoomCustomVideoCell"; 

    ZoomCustomVideoCell *cell = (ZoomCustomVideoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[NSBundle mainBundle] loadNibNamed:@"ZoomCustomVideoCell" owner:self options:nil] objectAtIndex:0]; 

     cell.m_zoomMsg = [[[ZoomMessage alloc] init] autorelease]; 
     [[cell m_zoomMsg] initWithJSON:[m_tmpVideoList objectAtIndex: indexPath.row]]; 
     [[cell videoLabel] setText:[cell.m_zoomMsg _from]]; 
     [[cell m_labelLocation] setText:[NSString stringWithFormat:@"%@", cell.m_zoomMsg._location]]; 
     [[cell videoLabelB] setText:[cell.m_zoomMsg _uploadDesc]]; 
     NSLog(@"UserName: %@", [[cell videoLabel] text]); 

     [cell refreshImage]; 

    } 

    return cell; 
} 
+0

檢查ZoomCustomVideoCell廈門國際銀行裏面的ReuseIdentifier是「ZoomCustomVideoCell」 – Ashishail

回答

0

解決此行導致內存泄漏:

cell = [[[NSBundle mainBundle] loadNibNamed:@"ZoomCustomVideoCell" owner:self options:nil] objectAtIndex:0]; 

將其更改爲:

cell = [[[[NSBundle mainBundle] loadNibNamed:@"ZoomCustomVideoCell" owner:self options:nil] objectAtIndex:0] autorelease]; 
+2

沒有幫助,但它崩潰的應用程序,我認爲這是對自己的自動釋放。 –

+0

請刪除if塊中的所有其他代碼,然後檢查 –

1

loadNibNamed:owner:options:方法需要爲owner:通過爲「文件的所有者筆尖」的說法。這意味着筆尖上的插座將連接到您作爲所有者傳遞的任何東西。由於您通過self作爲所有者,它將覆蓋以前分配給self的任何以前分配的插座,以及來自新加載的筆尖的插座。要建立插座連接,筆尖加載器使用提供的所有者上的setValue:forKey:。如果您已經將店鋪設置爲具有正確內存管理的屬性,那麼應該不會泄漏。如果你只有實體變量作爲實例變量,那麼(它不清楚,但我假設)這些對象在設置時會自動保留。

這裏有兩個解決方案:

  1. 您網點,例如提供正確的內存管理將它們轉換成屬性,如果它們尚未確保它們具有正確的內存管理屬性。

  2. loadNibNamed:owner:options:方法提供不同的所有者,該方法尚未建立任何銷售點,並且您知道將會適當地處理網點。