在使用以下代码推送后弹出我的视图控制器类的dealloc方法:
self.playerViewController = [[VideoPlayerViewController alloc] init];
[self.playerViewController set_video:video];
[self.navigationController pushViewController:self.playerViewController animated:YES];
[self.playerViewController release];
但是,如果我将推送代码更改为以下内容,则在弹出视图控制器后会正确调用dealloc:
playerViewController = [[VideoPlayerViewController alloc] init];
[playerViewController set_video:video];
[self.navigationController pushViewController:playerViewController animated:YES];
[playerViewController release];
我以为我理解使用点符号/ self,但显然不是。谁能在这里解释这个问题呢?
这是属性:
@property (nonatomic, retain) VideoPlayerViewController *playerViewController;
这是合成:
@synthesize playerViewController;
答案 0 :(得分:3)
你要保留两次。
self.playerViewController = [[VideoPlayerViewController alloc] init];
^ retain + 1 ^^^^^ retain + 1
但你只发布一次。
要修复内存管理问题,您可以将代码更改为以下内容:
self.playerViewController = [[[VideoPlayerViewController alloc] init] autorelease];
许多人说[self.foo release]
是不好的风格。您应该考虑将其替换为[foo release]