我对内存管理技术仍然不是很好,想知道是否有人可以向我解释这种奇怪的行为。考虑一下我一直在测试的这 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]);
这记录:保留计数= 1。不应该是0吗?
DofView* dofView = [[DofView alloc] initWithNibName:@"DofView" bundle:nil];
[self.navigationController pushViewController:dofView animated:YES];
NSLog(@"dof retian count = %d", [dofView retainCount]);
此日志:保留计数 = 5。我不知道为什么它是 5?
任何人都可以对此有所了解吗?我担心每次创建新视图时都会占用内存。
谢谢!