【发布时间】:2010-11-22 09:50:19
【问题描述】:
我在 tableView:cellForRowAtIndexPath: 中运行以下代码:
File *file = [[File alloc] init];
file = [self.fileList objectAtIndex:row];
UIImage* theImage = file.fileIconImage;
cell.imageView.image = theImage;
cell.textLabel.text = file.fileName;
cell.detailTextLabel.text = file.fileModificationDate;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
我运行了泄漏工具,发现 File 对象正在泄漏,因为我没有释放它。所以我在返回我认为安全的单元格之前添加了释放(如下所示):
File *file = [[File alloc] init];
file = [self.fileList objectAtIndex:row];
UIImage* theImage = file.fileIconImage;
cell.imageView.image = theImage;
cell.textLabel.text = file.fileName;
cell.detailTextLabel.text = file.fileModificationDate;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[file release];
return cell;
现在,当我运行应用程序时,它崩溃了。 UITableViewCells 是否仍在引用文件对象?在这里使用什么方法来确保我没有泄漏内存?
【问题讨论】:
标签: iphone objective-c xcode memory-leaks