【发布时间】:2011-07-20 17:09:14
【问题描述】:
我在 xcode 中通过分析发现了内存泄漏问题。这个问题很简单,但我不明白如何解决它:
考虑一个带有 2 个按钮和一个 tableview 的 uiviewcontroller。 button1=从服务器加载 JSON 数据并将单元格添加到 tableview 然后 [tableview reloadData]
button2=从另一个服务器加载 JSON 数据并将单元格添加到 tableview 然后重新加载。
好的,问题出在:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....
.....
NSURL *url = [NSURL URLWithString:stringpath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img;
if(!data) img=[UIImage imageNamed:@"small.jpg"];
else img= [[UIImage alloc] initWithData:data];
cell.imageView.image = img;
好的,如果我每次切换时都用 2 个按钮开始切换,我会从 UIImage 泄漏,所以我认为我需要在重新加载之前“清除”(释放)所有单元格数据?
谢谢
【问题讨论】:
标签: iphone ios memory-leaks tableview