Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 575
Jessedc Avatar asked Nov 20 '09 03:11

Jessedc


1 Answers

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.

like image 140
Manjunath Avatar answered Sep 28 '22 01:09

Manjunath