简体   繁体   English

保留NavigationController和window的数量为3

[英]Retain count of navigationcontroller and window is 3

I am developing an iPhone application which is navigation based. 我正在开发一个基于导航的iPhone应用程序。 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? 每当应用程序退出时,导航控制器和窗口的保留计数为3。有人可以向我解释如何解决此问题吗? The dealloc method, as a result, is not getting called. 结果,未调用dealloc方法。

There is no issue. 没有问题。

  • You should try not to concern your self with retain counts unless you see a definitive leak (usually in Instruments) 除非看到确定的漏洞(通常是在Instruments中),否则您应该尽量不要将自己与保留数相关联
  • You don't need to worry about objects like your window (and, probably, your nav controller) being dealloc'd at application quit-time; 您无需担心在应用程序退出时诸如窗口(可能还有您的nav控制器)之类的对象被取消分配。 ALL of your app's memory will go away at that time. 届时,您所有应用程序的内存都会消失。

But none of the dealloc methods, neither for the UIViewController's nor the Appdelegate's are being called. 但是没有调用dealloc方法,无论是针对UIViewController的方法还是Appdelegate的方法都没有被调用。 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. 视图控制器的keepcount值为1。问题是,我将它们保留在rootviewcontroller中,因为它们将被一次又一次地使用,释放它们并再次分配它们是la脚的。 So, when do I release these other UIViewControllers? 那么,什么时候发布这些其他UIViewControllers? The dealloc method of the rootviewcontroller is not being called. 不会调用rootviewcontroller的dealloc方法。

You overcome this issue by not depending on dealloc methods being called. 通过不依赖于调用dealloc方法来克服此问题。 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. 对象的dealloc应该只执行释放该对象的内存并履行其在内存管理契约中的dealloc所必需的操作。 When your app is terminated, all its memory is freed, so there's no need for dealloc to be called. 当您的应用终止时,其所有内存都被释放,因此无需调用dealloc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM