UIViewController 没有被释放

发布于 2024-12-13 09:57:18 字数 908 浏览 0 评论 0原文

我试图将自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美羊羊 2024-12-20 09:57:18

你的 alloc 和 init 给它一个保留计数 1,通过 CustomViewController 属性再次给它一个保留消息,把它带到 2。

你需要执行以下操作,在某个时候释放....

self.CustomViewController = nil;

虽然我不确定为什么你要存储对它的引用......?!

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....

self.CustomViewController = nil;

Although I am not sure why you are event storing a reference to it...?!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文