I\'ve looked through lots of posts, my books and Apple Developer and gleaned most of the understanding I need on use of these. I would be really grateful if some kind person co
didReceiveMemoryWarning
...
Action - Release anything you do not need, likely to be undoing what you might have set up in viewDidLoad.
This is wrong. Anything that you recreate in viewDidLoad
should be released (and set to nil
) in viewDidUnload
. As you mention below, didReceiveMemoryWarning
is also called when the view is visible. In didReceiveMemoryWarning
, you should release stuff like caches or other view controllers you are holding on to that can be recreated lazily the next time they are required (i.e., by implementing their getter manually).
viewDidUnload
...
Action - generally any IBOutlets you release in dealloc, should also be released (and references set to nil) in this method. Note that if the properties are set to retain, then setting them to nil will also release them.
Correct. Generally, everything you create in viewDidLoad and all IBOutlets that are declared as retain
should be released and set to nil
here.
dealloc
...
Action - release all objects that have been retained by the class, including but not limited to all properties with a retain or copy.
Correct. It's worth noting that this includes all objects you handle in viewDidUnload
because the latter is not implicitly called in the dealloc
process (AFAIK, not entirely sure). That's why it is essential to set all releases objects to nil
in viewDidUnload
because otherwise you risk releasing something twice (first in viewDidUnload
, then again in dealloc
; if you set the pointer to nil
, the release call in dealloc
will have no effect).
Popping View Controllers and Memory
Question 2 - Does popping a view remove it from memory?
Not necessarily. That is an implementation detail that you should not be concerned about. Whatever the current practice is, Apple could change it in the next release.