UIViewController pushViewController高保留View控制器的数量

Lol*_*z89 0 objective-c uinavigationcontroller pushviewcontroller ios retaincount

我写了下面这段代码:

-(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];
}
Run Code Online (Sandbox Code Playgroud)

两个日志的结果按顺序16!这怎么可能?我只调用一次alloc方法并在将控制器推到堆栈后释放.. alloc-> + 1,push-> + 1,release-> -1 = 1或不?

当我将它从堆栈中弹出时,我希望视图控制器是dealloc'd ..

SVG*_*reg 6

请在此问题中阅读此说明.它是NSObject协议参考的一部分:

重要说明:此方法在调试内存管理问题时通常没有价值.因为任何数量的框架对象可能保留了一个对象以保存对它的引用,而同时自动释放池可能在对象上保留任意数量的延迟版本,所以您不太可能从此获取有用信息方法.

NSObject协议参考.RetainCount讨论

  • 我希望更多的人能够投票.`retainCount`是一个无用的属性,应该永远不会出现在公共SDK中. (3认同)