如何解决iphone:在表视图的情况下会消耗大量内存并导致泄漏
| 我正在准备这样的自定义单元格 1)用Xib创建一个自定义单元 2)因为我必须更改自定义单元格中与从数据库读取的值相对应的标签内容。我无法重复使用相同的cellIdentifierstatic NSString *MyIdentifier = @\"MyIdentifier\";
MyIdentifier = [NSString stringWithFormat:@\"Cell %d\",indexPath.row];
NSString *offendersImagePath = [self applicationDocumentsDirectory];
offendersImagePath=[offendersImagePath stringByAppendingPathComponent:@\"Images\"];
CustomOffendersCell *cell = (CustomOffendersCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@\"CustomOffendersCell\" owner:self options:nil];
cell = aCustomOffendersCell;
aCustomOffendersCell=nil;
}
NSMutableArray *tempArray;//=[[NSMutableDictionary alloc] init];
tempArray=[offendersNamesList objectAtIndex:indexPath.row];
当我在仪器中检查此东西时,代码就像上面一样,显示此行的泄漏和高内存消耗
[[NSBundle mainBundle] loadNibNamed:@\"CustomOffendersCell\" owner:self options:nil];
你能建议我一些办法摆脱这个
解决方法
您应该为\“ [aCustomOffendersCell release] \”之类的单元格调用\“ release \”方法。
另外,您还必须释放单元格中已分配的所有数据,例如UILabel,UIImageView等。因此,当您将其放入单元格中时,然后释放所有这些数据。
希望对您有帮助。让我知道更多细节。
, 您应该在
aCustomOffendersCell
上调用自动释放,而不仅仅是分配nil
。
aCustomOffendersCell nil;
在下面使用
[aCustomOffendersCell autorelease];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。