导航控制器和窗口的保留计数为3
我正在开发一个基于导航的 iPhone 应用程序。每当应用程序退出时,导航控制器和窗口的保留计数都是 3。有人可以解释我如何克服这个问题吗?因此,dealloc 方法不会被调用。
I am developing an iPhone application which is navigation based. Whenever the application quits, the retain count of the navigation controller and the window is 3. Can somebody explain me how to overcome this issue? The dealloc method, as a result, is not getting called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有问题。
There is no issue.
但是没有调用 UIViewController 和 Appdelegate 的 dealloc 方法。视图控制器的保留计数值为 1。问题是,我将它们保留在 rootviewcontroller 中,因为它们会一次又一次地使用,释放它们并再次分配它们会很蹩脚。那么,我什么时候释放这些其他 UIViewController? rootviewcontroller 的 dealloc 方法没有被调用。
But none of the dealloc methods, neither for the UIViewController's nor the Appdelegate's are being called. The retaincount values of the view controllers are 1. The problem is, I retain them in a rootviewcontroller as they would be used again and again, and it would be lame to release them and allocate them again. So, when do I release these other UIViewControllers? The dealloc method of the rootviewcontroller is not being called.
您可以通过不依赖调用的 dealloc 方法来克服此问题。应用程序拆卸代码应放入适当的应用程序方法中。对象的dealloc 应该只执行释放该对象的内存并履行其在内存管理契约中的部分所需的操作。当您的应用程序终止时,其所有内存都会被释放,因此无需调用 dealloc。
You overcome this issue by not depending on dealloc methods being called. Application teardown code should go in the appropriate application methods. An object's
dealloc
should just do what's necessary to release that object's memory and fulfill its part in the memory management contract. When your app is terminated, all its memory is freed, so there's no need for dealloc to be called.