title: didReceiveMemoryWarning, viewDidUnload and dealloc
body: <p>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 could confirm that I've got it right (or correct me) and also answer the two questions.</p>
  
  <p>Many thanks,</p>
  
  <p>Chris.</p>
  
  <p><strong>Order of Messages</strong>
  Generally, the messages will appear in the following order:</p>
  
  <ul>
  <li><p>didReceiveMemoryWarning</p></li>
  <li><p>viewDidUnload (which can be caused by 1) - obviously only applies to View    Controller Classes.</p></li>
  <li><p>dealloc</p></li>
  </ul>
  
  <p><strong>didReceiveMemoryWarning</strong></p>
  
  <p>Called when the system is low on memory.  </p>
  
  <p>By default, view controllers are registered for memory warning notifications and within the template method, the call to [super didReceiveMemoryWarning] releases the view if it doesn't have a superview, which is a way of checking whether the view is visible or not.  It releases the view by setting its property to nil.</p>
  
  <p>Action - Release anything you do not need, likely to be undoing what you might have set up in viewDidLoad.  Do not release UI elements as these should be released by viewDidUnload.</p>
  
  <p><em>Question1 - It seems that this will be called even if the View is visible, so its difficult to see what you could safely release.  It would be really helpful to understand this and some examples of what could be released.</em></p>
  
  <p><strong>viewDidUnload</strong> </p>
  
  <p>Called whenever a non visible View Controller's View property is set to nil, either manually or most commonly through didReceiveMemoryWarning.</p>
  
  <p>The viewDidUnload method is there so that you can:
  - clean up anything else you would like, to save extra memory or
  - if you've retained some IBOutlets, to help free up memory that wouldn't otherwise be released by the view being unloaded.</p>
  
  <p>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.</p>
  
  <p><strong>dealloc</strong></p>
  
  <p>Called when the view controller object is de-allocated, which it will be when the retain count drops to zero.</p>
  
  <p>Action - release all objects that have been retained by the class, including but not limited to all properties with a retain or copy.</p>
  
  <p><strong>Popping View Controllers and Memory</strong></p>
  
  <p><em>Question 2 - Does popping a view remove it from memory?</em></p>