NB: I saw a few questions being asked in this front, but none seem to have clarified my doubt.
Pre iOS6, all outlets, heavy resources like images and sounds were set to nil in viewDidUnload. Post iOS6, this is no more the case as views are not unloaded anymore. The system calls didReceiveMemoryWarning and this is the new recommended place to put such resource neutralizations.
So what if the code needs to support everything above iOS4? On devices running iOS 4 and 5, viewDidUnload will still be getting called. And in devices running iOS6, only didReceiveMemoryWarning will be called.
Does this mean I have to replicate the code in both places? Is calling a common method in both places a good approach? Please provide your inputs or approaches on how this is being handled in the industry.
Yes, if you’re supporting iOS versions prior to 6.0, you should remove anything that’s dependent upon the view and its controls in
viewDidUnload. It’s a function of the iOS running on the device. Obviously, if the device is running 6.0 or later, the view won’t be unloaded, though. Regardless, you should purge caches and the like indidReceiveMemoryWarning.You should not replicate the code in the two methods as that’s unnecessary. Do view-related cleanup in
viewDidUnloadand cache-related purging indidReceiveMemoryWarning. And, most importantly, do not copy view-specific cleanup fromviewDidUnload(such as settingIBOutletreferences tonil, something that Interface Builder used to add to our code) intodidReceiveMemoryWarning. If you do and if you get a memory warning in iOS 6, you’ll loseIBOutletreferences for a view that has not been removed.See iOS 6 – viewDidUnload migrate to didReceiveMemoryWarning?