【发布时间】:2012-04-29 15:15:09
【问题描述】:
UITableview 每次滚动,都会有 48 个字节的内存泄漏。 负责库:libsystem_c.dylib 负责框架:strdup。
这仅在 iOS 5.1 上观察到,而不在早期版本上观察到。 其他人也面临同样的问题吗?这是 iOS 5.1 中的错误吗?
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath
{
NSString *cellIdentifier = [[NSString alloc] initWithString:@"fontSelectionCell"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
[cellIdentifier release];
if (cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
cell.textLabel.text = [fontNameList objectAtIndex:[indexPath row]];
cell.selectionStyle =UITableViewCellSelectionStyleGray;
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
if ([fontName isEqualToString:cell.textLabel.text])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.textLabel.textColor = [UIColor blueColor];
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.textColor = [UIColor blackColor];
}
return cell;
}
【问题讨论】:
-
显示一些代码可能是什么? cellForRowAtIndexPath: 方法会是最有趣的......你也在你的项目中使用 ARC 吗?
-
您是否使用了没有自定义代码的默认实现?是泄漏,还是稍后会清除内存(因为自动释放的对象)。
-
@jaydee3,我用基本表格视图测试了一个简单的应用程序,但内存泄漏仍然存在。
-
我也看到了这个问题,在极少数情况下,当一直向上滚动并弹跳然后一直滚动到底部时,它会导致多次泄漏,并在某一时刻用 SIGKILL 杀死了应用程序。
标签: ios uitableview memory-leaks