iPhone - 我应该在其 dealloc 方法中手动释放我的 customViewController 的视图吗?

发布于 2024-11-26 09:57:31 字数 208 浏览 1 评论 0原文

我正在使用导航控制器将自定义 viewController 推送到屏幕上。当我完成并将其弹出时,我发现为 customViewController 调用了 dealloc 方法,但从未调用“viewDidUnload”方法。这是否意味着视图仍然存在?如果是这样,这对我来说可能是一个记忆问题。如果是这种情况,我应该在 customViewContoller 的 dealloc 方法中释放视图吗?谢谢。

I'm using a navigation controller to push a custom viewController onto the screen. When I'm done and pop it off, I find that the dealloc method is called for the customViewController, but the "viewDidUnload" method is never called. Does this mean that the view is still there? This could be a memory problem for me if so. If this is the case, should I then release the view in my dealloc method in my customViewContoller? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

世态炎凉 2024-12-03 09:57:31

这是没有必要的。当您的 UIViewController 子类收到 -dealloc 时,您应该释放所有保留的属性。然后它将到达[super dealloc]。不能肯定地说,但 UIViewController 上的 -dealloc 也应该处理转储所有保留的属性。这样你的观点就会得到适当的释放。

不确定为什么 -viewDidUnload 没有被调用,但这应该不重要。也许,如果您的应用程序的内存压力较低,当您弹出视图控制器时,视图可能会被卸载,而无需释放整个控制器。

This isn't necessary. When your UIViewController subclass receives -dealloc, you should be releasing any retained properties. It will then get to [super dealloc]. Can't speak with certainty, but -dealloc on UIViewController should handle dumping all of it's retained properties as well. Thus your view will be released appropriately.

Not sure why -viewDidUnload isn't getting called, but it shouldn't matter. Perhaps if your app's memory pressure was lower when you pop the view controller, the view may get unloaded without deallocating the entire controller.

忆梦 2024-12-03 09:57:31

通常,您会在按下视图控制器后释放它。例如:

UIViewController *myVC = [[UIViewController alloc] init];
[[self navigationController] pushViewController:myVC animated:YES];
[myVC release];

Typically you release the view controller after you push it. For example:

UIViewController *myVC = [[UIViewController alloc] init];
[[self navigationController] pushViewController:myVC animated:YES];
[myVC release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文