【发布时间】:2013-01-29 06:27:16
【问题描述】:
-(void)NewButton
{
ApplianceViewController *VC = [[ApplianceViewController alloc] initWithNibName:@"ApplianceViewController" bundle:[NSBundle mainBundle]] ;
NSLog(@"Retain count before pushViewController:%d",VC.retainCount);//prints1
[self.navigationController pushViewController:VC animated:YES];
NSLog(@"Retain count after pushViewController:%d",VC.retainCount);//prints 7
[VC release];
NSLog(@"Retain count after Release:%d",VC.retainCount);// prints 6
}
在我的代码中,保留计数异常增加。我浪费了很多时间。请帮忙。
【问题讨论】:
-
别担心 :) retainCount 只是一个实现细节,不要担心它所说的内容。您实际上只需要关注您的引用计数,即在您自己的代码中分配、复制或保留它的时间。
-
你不应该关心这个有几个原因。 1)您现在应该使用 ARC。 2)永远不要查看保留计数以进行正确的内存管理。 3)你不知道
UINavigationController的内部实现,所以你也不知道retainCount是否正确。 -
对,但在这种情况下,我正在处理 retainCount,因为 ApplianceViewController 的 dealloc 方法没有被调用,因为 retainCount 没有降至零,并且在一些导航后我面临内存崩溃问题。
-
在视图控制器从导航堆栈中弹出之前不会调用Dealloc。如果您确实有内存管理问题,它们不在此代码中。
-
目前我正在处理retainCount,因为ApplianceViewController的dealloc方法没有被调用(当我弹出它时)因为retainCount没有降为零。
标签: objective-c uinavigationcontroller retaincount