[英]iOS 5 cellForRowAtIndexPath Memory Leak
I have been testing the application on the device (iOS 5) while using Instruments and I found a couple of memory leaks. 使用Instruments时,我已经在设备(iOS 5)上测试了该应用程序,发现了几次内存泄漏。
This is the part of the code I'm being redirected to from Instruments (see the arrow for exact line): 这是我从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;
}
As you can see, I have a custom cell which is loaded from a NIB file. 如您所见,我有一个自定义单元,它是从NIB文件加载的。 There are three files for the cell (
customCell.m
, customCell.h
, customCell.xib
). 该单元有三个文件(
customCell.m
, customCell.h
, customCell.xib
)。 The thing is that I don't know if I have to release something in the cell controller (which is now empty, no methods), since this is iOS 5 with ARC. 事实是,我不知道是否必须在单元控制器中释放某些内容(现在为空,没有方法),因为这是带有ARC的iOS 5。
Take a look at the Table View Programming and how to load cells from NIB (XIB) files. 看一下“表视图编程”以及如何从NIB(XIB)文件加载单元。
https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1 https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1
The first thing weird is that you are storing the cell in a local variable. 奇怪的第一件事是您将单元格存储在局部变量中。 You should be wiring the custom cell up to a property in the class and all you call in your code is:
您应该将自定义单元格连接到类中的一个属性,并且您在代码中调用的全部是:
[[NSBundle mainBundle] loadNibNamed:@"CeldaUltimasFotosViewCell" owner:self options:nil];
Follow the code from Loading Custom Table-View Cells From Nib Files and you can't go wrong. 遵循从Nib文件加载自定义表格视图单元格中的代码,您不会出错。
check out my answer here: 在这里查看我的答案:
How can I recycle UITableViewCell objects created from a XIB? 如何回收从XIB创建的UITableViewCell对象?
you don't even need to use loadNibNamed any more on iOS5 您甚至不需要在iOS5上再使用loadNibNamed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.