iPhone - 我应该在其 dealloc 方法中手动释放我的 customViewController 的视图吗?
我正在使用导航控制器将自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是没有必要的。当您的 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.通常,您会在按下视图控制器后释放它。例如:
Typically you release the view controller after you push it. For example: