开发者

Are viewDidUnload and dealloc always called when tearing down a UIViewController?

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开发者_Python百科 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.


It is quite thoughtful that, viewDidiUnload method get only called when memory warning appears. Good practise would be to release requisite the object within this method and also make the object nil.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜