I'm new developer about to launch my first app. I'm confused about the deprecation of viewDidUnload
as described below in Apple's iOS 6 release notes:
In iOS 6, the viewWillUnload and viewDidUnload methods of UIViewController are now deprecated. If you were using these methods to release data, use the didReceiveMemoryWarning method instead. You can also use this method to release references to the view controller’s view if it is not being used. You would need to test that the view is not in a window before doing this.
Why is this happening? What guidelines should I follow to ensure that this change doesn't cause any performance issues in my app?
Thanks.
In iOS 6, views are never unloaded.
This means that
loadView
andviewDidLoad
are only ever called once, andviewDidUnload
is never called. So if your view controller usesviewDidUnload
to handle low memory conditions then it will need to change.If you want to respond to low memory conditions, implement
didReceiveMemoryWarning
and release your temporary data and objects in this method.In iOS 6 we should release views by ourself, do something like this
According to Apple, they have improved the internal memory management for views enough that the gains achieved by destroying stuff in
viewWill/DidUnload
are minimal. Furthermore, they have data suggesting that many apps crash because the apps do not properly handle those notifications, and do "other" stuff not associated with the view unloading.Finally, a memory warning is now verified as the first and only warning you will get before your app is terminated due to low memory, so it is really the place to handle memory issues.
So, basically, just remove your
viewWillUnload
andviewDidUnload
methods. Handle memory issues indidReceiveMemoryWarning
and any other view controller management in the appropriate places.EDIT
That depends. I know that's not what you want to hear, but it's the truth :-)
In general, you should avoid asymmetry. Thus, you should "undo" an operation using the symmetric method from which you "did" the original. In general, you should be able to do all the
viewDidUnload
type work indidReceiveMemoryWarning
anddealloc
.This should really not cause a change, because you had to duplicate most of that code in both of those places anyway.
I don't know what you mean by "going further down on the navigation controller stack" so you will need to clarify that example for me to provide a useful response.
One of the problems with using
viewDidDisappear
andviewDidAppear
was that it was hard to know when the view was appearing because it was actually appearing, or because a view that was on top of it was disappearing... causing it to appear.These pieces of API are supposed to help you address those issues: