导航控制器和窗口的保留计数为3

发布于 2024-08-15 18:44:56 字数 96 浏览 5 评论 0原文

我正在开发一个基于导航的 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 技术交流群。

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

发布评论

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

评论(3

夢归不見 2024-08-22 18:44:56

没有问题。

  • 你应该尽量不要担心保留计数,除非你看到明确的泄漏(通常在仪器中)
  • 你不需要担心像你的窗口(可能还有你的导航控制器)这样的对象在应用程序退出时被释放-时间;届时您应用程序的所有内存都将消失。

There is no issue.

  • You should try not to concern your self with retain counts unless you see a definitive leak (usually in Instruments)
  • You don't need to worry about objects like your window (and, probably, your nav controller) being dealloc'd at application quit-time; ALL of your app's memory will go away at that time.
栀子花开つ 2024-08-22 18:44:56

但是没有调用 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.

梦太阳 2024-08-22 18:44:56

您可以通过不依赖调用的 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.

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