What is the difference between applicationDidReceiveMemoryWarning
and didReceiveMemoryWarning
? 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 view controller receives 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With