In iOS 6 viewWillUnload and viewDidUnload Are Deprecated

Prior to iOS 6, in low memory conditions iOS would call viewWillUnload and viewDidUnload before releasing unneeded views from memory. Apple has determined that the memory captured was not worth the overhead and additional issues caused by using these methods.

Beginning in iOS 6, viewWillUnload and viewDidUnload are deprecated, as views are no longer removed from memory if the OS runs low on the same. Put another way, if your app targets iOS 6, these methods will not be called.

Apple recommends code that you had in these methods should be reviewed, and if needed, moved to dealloc, viewWillDisappear or viewDidDisappear.

Interesting note, Apple mentioned at WWDC 2012 that they fixed a whole class of application crashes by removing the calls to viewWillUnload and viewDidUnload.

Good to know that Apple continually reviews their API’s and sometimes an update equals removing code.

  1. I have many apps which run in iOS 5 and above. None of them have any code in viewDidUnload except for the call to super and setting a bunch of view elements to nil.

    I’ve been wondering if I should just get rid of viewDidUnload in my apps, or if I should keep it as long I’m still supporting iOS 5 and 5.1?

    • If you are not releasing memory in these methods, seems a safe bet to remove the code and these methods altogether.

  2. But Xcode still insert code into viewDidUnload if you create an outlet connection by dragging. Maybe because I’m targeting iOS 4.3 as minimum OS?

  3. What about cleaning up observers queues?
    eg. in a few viewDidUnload I added [[NSNotificationCenter defaultCenter] removeObserver:self]; where should these calls go now?

Comments are closed.