Hi all,
What is the difference between applicationDidReceiveMemoryWarning and didReceiveMemoryWarning ?
And what is the best way to handle those warnings.
Hi all,
What is the difference between applicationDidReceiveMemoryWarning and didReceiveMemoryWarning ?
And what is the best way to handle those warnings.
You should be using "Lazy loading" of data on all your views. for example, if you are displaying a list of data on a table view, you should release the data when your viewcontroller received a didReceiveMemoryWarning and set the data pointer to nil.
Most of the apple sample code emphasizes on this lazy loading technique.
applicationDidReceiveMemoryWarning is a similar message sent to your AppDelegate. You should release unwanted global data that you store in your AppDelegate.
A classic example is Safari. Open say 2-3 tabs in Safari (on iPhone Simulator). Let all the tabs load the web page content. Try switching between different tabs. You should notice that the content remains there and is not flushed. Now from the menu, close "Simulate Memory Warning". Now when you switch to a different tab, safari will fetch the contents again. Internally what has happened is that, the URL is remembered, but the entire web page contents was released in the didReceiveMemoryWarning method.
You should also implement similar mechanisms in your app.