【发布时间】:2011-08-22 09:34:24
【问题描述】:
我仍然对内存管理技术不太了解,想知道是否有人可以向我解释这种奇怪的行为。考虑一下我一直在测试的这 3 段代码:
DofView* dofView = [[DofView alloc] initWithNibName:@"DofView" bundle:nil];
NSLog(@"dof retain count = %d", [dofView retainCount]);
此日志:保留计数 = 1。这很好。
DofView* dofView = [[DofView alloc] initWithNibName:@"DofView" bundle:nil];
[dofView release];
NSLog(@"dof retain count = %d", [dofView retainCount]);
这个日志:retain count = 1。不应该是0吗??
DofView* dofView = [[DofView alloc] initWithNibName:@"DofView" bundle:nil];
[self.navigationController pushViewController:dofView animated:YES];
NSLog(@"dof retian count = %d", [dofView retainCount]);
这个日志:retain count = 5。我不知道为什么是 5 个?
任何人都可以对此有所了解吗?我担心每次创建新视图时都会占用内存。
谢谢!
【问题讨论】:
-
retainCount 永远不能返回 0
标签: iphone ios memory-management pushviewcontroller