繁体   English   中英

iOS 5 cellForRowAtIndexPath内存泄漏

[英]iOS 5 cellForRowAtIndexPath Memory Leak

使用Instruments时,我已经在设备(iOS 5)上测试了该应用程序,发现了几次内存泄漏。

这是我从Instruments重定向到的代码的一部分(请参见箭头以获取确切的行):

- (UITableViewCell *)tableView:(UITableView *)tableView
                         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      CeldaUltimasFotosViewCell *cell =
          (CeldaUltimasFotosViewCell *) [self.tableView 
                 dequeueReusableCellWithIdentifier:@"CeldaUltimasFotosViewCell"];

      if (cell == nil) {
- - - - > NSArray *topLevelObjects =
                       [[NSBundle mainBundle] 
                             loadNibNamed:@"CeldaUltimasFotosViewCell"
                                    owner:nil options:nil];
          cell = [topLevelObjects objectAtIndex:0];
      }

      // Configure the cell...
      [[cell titulo] setFont:fuente_titulo];
      ...
      return cell;
}

如您所见,我有一个自定义单元,它是从NIB文件加载的。 该单元有三个文件( customCell.mcustomCell.hcustomCell.xib )。 事实是,我不知道是否必须在单元控制器中释放某些内容(现在为空,没有方法),因为这是带有ARC的iOS 5。

看一下“表视图编程”以及如何从NIB(XIB)文件加载单元。

https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

奇怪的第一件事是您将单元格存储在局部变量中。 您应该将自定义单元格连接到类中的一个属性,并且您在代码中调用的全部是:

[[NSBundle mainBundle] loadNibNamed:@"CeldaUltimasFotosViewCell" owner:self options:nil];

遵循从Nib文件加载自定义表格视图单元格中的代码,您不会出错。

在这里查看我的答案:

如何回收从XIB创建的UITableViewCell对象?

您甚至不需要在iOS5上再使用loadNibNamed

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM