当我单击基于导航的应用程序上的后退按钮时,为什么未调用 viewdidunload 函数
您好,我想发布我的 fetchedResultsController
。
我想知道为什么当我在基于导航的应用程序上按后退按钮时不调用 viewdidunload 。或者我应该在其他地方释放它?
谢谢你的帮助
Hi I want to release my fetchedResultsController
.
I was wondering why is viewdidunload
not called when i push back button on navigation based application.or i should release it somewhere else?
thanks for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-viewDidUnload
仅保证在视图从内存中清除时被调用,并且 UIKit 框架可能会挂起它,以便在用户返回那里时快速呈现视图。要在视图消失时确定性地释放获取的结果控制器,请使用-viewWillDisappear:
或-viewDidDisappear:
。-viewDidUnload
is only guaranteed to be called when the view is purged from memory, and the UIKit framework might be hanging on to it in order to present the view quickly if the user goes back there. To deterministically release your fetched result controller when the view disappears, use-viewWillDisappear:
or-viewDidDisappear:
.如果您认为由于未调用 viewDidLoad 而导致泄漏,请检查您的controller.view removeFromSuperView 调用并确保您正在使用removeFromParentViewController。不要只是从超级视图中删除视图,而是从其父控制器中删除视图控制器。
If you think that you're having leaks because viewDidLoad isn't called, than check your controller.view removeFromSuperView calls and ensure that you're using removeFromParentViewController. Instead of just removing the view from superview remove your viewController from its parentController.
我发现在我的例子中发生了一些奇怪的事情:
dealloc
被调用,但viewDidUnload
没有被调用。但我认为出于内存管理目的我可以忍受这一点,因为那时我所有的强属性都将被释放(我正在使用 ARC)。
在您的情况下,我认为您还应该检查是否调用了
dealloc
并在那里释放您的fetchedResultsController
。I'm seeing something strange happening in my case:
dealloc
is called butviewDidUnload
don't.But I think I can live with that for memory management purposes because all my strong properties will be deallocated at that time (I'm using ARC).
In your case I think you should check also for
dealloc
being called and release yourfetchedResultsController
there.您可以从
-dealloc
中自行调用它。you can call it yourself from
-dealloc
.