title: iPhone Development - Simulate Memory Warning
body: <p><strong>Background</strong>:</p>
  
  <p>I have a tab bar application. Each tab contains navigation controller allowing the user to transition from one view to the other showing a drill down information of the data (each view is being handled by a view controller and each view controller class has <code>didReceiveMemoryWarning</code> method). Lists are populated by pulling the data from web services.</p>
  
  <p><strong>Problem</strong>:</p>
  
  <p>When i use "Hardware > Simulate Memory Warning" option of iPhone Simulator, the <code>didReceiveMemoryWarning</code> method is called for ALL my view controllers - even the one which the user is viewing. I don't want to clear any content which is being used by the active view controller. How can I achieve that? </p>
  
  <p>Which method should have the implementation to reload the data after the data was released because of memory warning? (I see that the view controller classes that contain a table view call <code>viewDidLoad</code> method when user comes back to that view, but if the view contains (say UIWebView) then <code>viewDidLoad</code> method is not called. Why is that?) </p>
  
  <p><strong>Edited (Friday 30 January 2009 - 03:10 PM)</strong></p>
  
  <p>(Note: I'm using Interface builder for creating views, and <code>loadView</code> method is commented out.)</p>
  
  <p>So, when a view controller receives a memory warning message, these are the steps that are carried out:</p>
  
  <ol>
  <li><p>Following method is called:</p>
  
  <pre><code>- (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning]; 
  }
  </code></pre></li>
  <li><p>As a result of call to <code>[super didReceiveMemoryWarning]</code>, <code>[self setView:nil]</code> gets automatically called?</p></li>
  <li><p>If any resources should be cleared, then <code>setView</code> method should be overwritten to clear local resources. </p></li>
  <li><p><code>[self setView:nil]</code> is not called if the view is currently active (By default). Right? - I'm really curious which method takes this decision and how?</p></li>
  </ol>
  
  <p>Can you please confirm. Plus, I was getting an error following this approach but adding <code>myObject = nil</code> after releasing <code>myObject</code> in <code>dealloc</code> method of controller class fixed the issue. Thanks.</p>