【发布时间】:2012-04-02 01:53:14
【问题描述】:
简单场景:表格视图控制器,有 5000 行。 我有 5000 个图像名称,从 0.png 到 4999.png。
这是我的 cellForRowAtIndexPath: 方法:
静态 NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *string = [NSString stringWithFormat:@"%d",indexPath.row];
UIImage *img = [UIImage imageNamed:string];
if (img) {
cell.imageView.image = img;
} else {
cell.imageView.image = [UIImage imageNamed:@"NoPhotoDefault"];
}
return cell;
我已经分析了仪器的行为,它表明实际内存使用量在滚动时快速上升,并且从未下降。
它从大约 8 MB 开始,到达最后一行时增加到 200 MB。
我在这里错过了什么?
谢谢
附: Proj 基础 sdk 为 5.0,使用 ARC。
稍后编辑,在后台发送应用程序时,内存被释放。
【问题讨论】:
-
已有答案here
标签: ios image uitableview memory-management automatic-ref-counting