UIViewController 没有被释放
我试图将自定义 UIViewController 类弹出到导航控制器,然后当不再查看该弹出控制器时,将其释放。然而,视图控制器仍然存在,我不知道为什么。任何帮助将不胜感激。
接口:
@property (nonatomic, retain) CustomViewController *viewcontroller;
实现:
CustomViewController *vc = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
self.CustomViewController = vc;
[vc release]; // Release this after setting property to avoid memory leak.
[[self navigationController] pushViewController:[self.CustomViewController autorelease] animated:YES];
// Push in the next view. My thinking is that since pushViewController retains this view, if I autorelease when I send the view, the only thing still retaining the view when it shows up will be the navigation controller, and thus when it is bounced back off of the navigation stack, it should be deallocated. But apparently that's not happening..
I'm trying to have a custom UIViewController class get popped to the navigation controller, and then when that popped controller is no longer being viewed, have it be deallocated. However, the view controller is sticking around and I'm not sure why. Any help would be appreciated.
Interface:
@property (nonatomic, retain) CustomViewController *viewcontroller;
Implementation:
CustomViewController *vc = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
self.CustomViewController = vc;
[vc release]; // Release this after setting property to avoid memory leak.
[[self navigationController] pushViewController:[self.CustomViewController autorelease] animated:YES];
// Push in the next view. My thinking is that since pushViewController retains this view, if I autorelease when I send the view, the only thing still retaining the view when it shows up will be the navigation controller, and thus when it is bounced back off of the navigation stack, it should be deallocated. But apparently that's not happening..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 alloc 和 init 给它一个保留计数 1,通过 CustomViewController 属性再次给它一个保留消息,把它带到 2。
你需要执行以下操作,在某个时候释放....
虽然我不确定为什么你要存储对它的引用......?!
Your alloc and init give it a retain count of 1, going throught the CustomViewController property gives it a retain message again, taking it to 2.
You need to do the following, at some point to release....
Although I am not sure why you are event storing a reference to it...?!