【发布时间】:2012-03-04 12:51:00
【问题描述】:
我写了以下代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
GameViewController *gameViewController = [[GameViewController alloc]initWithLevelNumber:([levelGroup intValue]*100+indexPath.row) Bonus:NO];
NSLog(@"Retain Counter =%d",gameViewController.retainCount);
[navController pushViewController:gameViewController animated:YES];
[gameViewController release];
NSLog(@"Retain Counter=%d",gameViewController.retainCount);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
两个日志的结果依次为1和6! 这怎么可能?我只调用一次alloc方法并在将控制器压入堆栈后释放.. alloc-> +1,push-> +1,release-> -1 = 1?
当我将视图控制器从堆栈中弹出时,我希望它被释放。
【问题讨论】:
-
尝试将其更改为自动释放,看看会发生什么
-
不要使用
retainCount来检查泄漏。使用仪器工具。搜索“retaincount”,你会发现很多很多原因,为什么它在 99% 的时间里都是一个糟糕的属性。在有用的 1% 的时间里,这不值得麻烦。
标签: objective-c ios uinavigationcontroller pushviewcontroller retaincount