使用自点符号不会调用 dealloc
使用以下代码推送后弹出时,不会调用我的视图控制器类的 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;
The dealloc method of my view controller class is not called when popped after being pushed with the following code:
self.playerViewController = [[VideoPlayerViewController alloc] init];
[self.playerViewController set_video:video];
[self.navigationController pushViewController:self.playerViewController animated:YES];
[self.playerViewController release];
However if I change the push code to the following, then my dealloc is called appropriately after the view controller is popped:
playerViewController = [[VideoPlayerViewController alloc] init];
[playerViewController set_video:video];
[self.navigationController pushViewController:playerViewController animated:YES];
[playerViewController release];
I thought I understood the use of dot notation/self, but obviously not. Can anyone explain the problem here?
Here is the property:
@property (nonatomic, retain) VideoPlayerViewController *playerViewController;
and here is the synthesize:
@synthesize playerViewController;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你保留了两次。
但你只释放一次。
要解决内存管理问题,您可以将代码更改为如下所示:
许多人说
[self.foo release]
是不好的风格。您应该考虑将其替换为[foo release]
You are retaining twice.
But you only release one time.
To fix your memory management issue you could change the code to something like this:
And many people say
[self.foo release]
is bad style. You should consider to replace it with[foo release]