ViewDidUnload deprecation and backward compatibility

NB: I have seen several questions asked on this front, but no one seems to have clarified my doubts.

Pre iOS6, all outputs, heavy resources, such as images and sounds that have been installed on nil

in viewDidUnload

. Publish to iOS6, this is no longer the case as views are not being paged out anymore. The system calls didReceiveMemoryWarning

and this is the new recommended place to neutralize resources.

So what if the code needs to support everything above iOS4? On devices running iOS 4 and 5 it will still be called viewDidUnload

. And in devices running iOS6 will only be called didReceiveMemoryWarning

.

Does this mean that I need to copy the code in both places? Does a common method in both places call a good approach? Please provide your input or approaches to how this is handled in the industry.

+3


source to share


2 answers


Yes, if you support iOS versions prior to 6.0, you must remove everything that depends on the view and its controls in viewDidUnload

. This is an iOS feature that runs on the device. Obviously, if the device is running 6.0 or newer, the view will not be unloaded. Regardless, you have to clear caches, etc. In didReceiveMemoryWarning

.

You shouldn't copy code in two methods as unnecessary. Do a browse-related cleanup in viewDidUnload

and a cache-related cleanup in didReceiveMemoryWarning

. And most importantly, don't copy the view-specific cleanup from viewDidUnload

(for example, set IBOutlet

references to nil

something that Interface Builder used to add to our code) to didReceiveMemoryWarning

. If you do, and if you get a memory saving warning in iOS 6, you will lose links IBOutlet

for a view that has not been deleted.



See iOS 6 - viewDidUnload go to didReceiveMemoryWarning?

+4


source


didReceiveMemoryWarning

is available in iOS 2.0 and later, so why not move it from viewDidUnload

to didReceiveMemoryWarning

for everyone?



+1


source







All Articles