[英]UITableView Cells not doing dealloc
我正在使用显示图像的自定义单元格构建UItableView。 问题在于,当我向下滚动时,以前的单元似乎没有进行取消分配,并且设备内存已满。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
CustomTableCellView *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CustomTableCellView alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
Article *tempArticle = [_objects objectAtIndex:indexPath.row];
cell.titel.text = tempArticle.title;
cell.subTitle.text = tempArticle.subTitle;
cell.category.text = tempArticle.category;
if(tempArticle.imageUrl){
[cell.image setImageWithURL:[NSURL URLWithString:tempArticle.imageUrl]];
} else {
cell.image.image = [UIImage imageNamed:@"video"];
}
return cell;
}
如上所述,您正在正确设置重用标识符。
也许是因为您正在使用AFNetworking库并下载单元格的图像而填满了内存? 请更准确地定义“填满内存”。
我99%确信内存增加是由于图像加载和缓存所致。 AFnetworking
正在使用NSCache
实例缓存下载的图像,该缓存在内存中执行,并且当系统确定内存不足时将耗尽该缓存,这不是问题。
同样, imageNamed
方法缓存以与AFNetworking
相同的方式加载的图像。
为了检查是否有泄漏或数据无法正常工作,请在向上滚动后检查内存是否增加,如果内存保持不变,则表示没有问题或泄漏(也您可以使用仪器检查泄漏),则缓存的图像会导致内存增加。
还要从堆栈中删除视图控制器(弹出,删除),这将导致文本,标签或其他数据(不是图像)上的某些重新分配,如果内存减少(不会大幅减少),则说明您处于正确的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.