Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between applicationDidReceiveMemoryWarning , didReceiveMemoryWarning?

What is the difference between applicationDidReceiveMemoryWarning and didReceiveMemoryWarning? What is the best way to handle those warnings?

like image 782
raaz Avatar asked Feb 20 '10 12:02

raaz


1 Answers

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.

like image 126
Mugunth Avatar answered Sep 22 '22 14:09

Mugunth