本文介绍了当删除UIViewController时,viewDidUnload和dealloc总是被调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 viewDidUnload dealloc 是否总是在UIViewController下拉过程中连续调用。是否可能在我的视图控制器上调用 dealloc ,而没有先调用 viewDidUnload



在任何一种情况下,如果我在两个方法中安全地释放属性和保留的引用,那么如果两个方法都被调用就不是一个问题 - 但我想知道是否有人知道

2012更新:很方便地注意到,就像iOS 6 viewDidUnload 已弃用,应在 didReceiveMemoryWarning 中替换为手动查看(如果需要)



关于新的UIView / UIViewContoller的一篇好文章和新的行为,它对

解决方案

viewDidUnload 不会每次调用 dealloc 方法。 viewDidUnload 仅在您的应用程式收到低记忆警告时呼叫!



只要想想,如果你在 viewDidUnload dealloc 方法。如果每次都调用,那么你正在释放已经释放的对象,这将导致应用程序崩溃,不是吗? viewDidUnload 是苹果提供的一个地方,当收到低内存警告,因为你知道在iPhone我们有内存限制清理的东西。


I'd like to know whether or not both viewDidUnload and dealloc are always called in succession in the UIViewController tear-down process. Is it possible that dealloc could be called on my view controller without viewDidUnload having been called first?

In either case, if I am safely releasing the properties and retained references in both methods it wouldn't be a problem if both methods were called -- but I was wondering if anyone knew for sure or could shed some light on the tear-down process.

2012 Update: It's handy to note that as if iOS 6 viewDidUnload has been deprecated and should be replaced with manual view teardown if required in didReceiveMemoryWarning.

A good article on the new UIView/UIViewContoller and the new behaviour and it's effects on the joe conway blog

解决方案

viewDidUnload will not be called every time like dealloc method. viewDidUnload is called only when your app receives low memory warning!

Just think, if you are releasing your object both in viewDidUnload and dealloc methods. If both gets called every time, then you are releasing already released object, which will lead to application crash, isn't it?. viewDidUnload is a place provided by the Apple for cleaning up the things when receiving the low memory warning because you know in iPhone we have memory restriction.

这篇关于当删除UIViewController时,viewDidUnload和dealloc总是被调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 23:15