What to do when my app receives memory warning?

ipad, iphone, memory, memory-management

Solution

It all depends on your app, usually you don't have to do anything special except following Apple's recommended practices.

ViewControllers which are not visible at the moment will get `didReceiveMemoryWarning` message. By default (calling `[super didReceiveMemoryWarning]`) controller's view is unloaded (released, freed). As the view is unloading, view controller receives `viewDidUnload` where you should release all your IBOutlets (or otherwise retained UI elements). Only then the view can completely be deallocated and memory freed.

In the `didReceiveMemoryWarning` you should also free as much data as you can - if you store some part of data model in ViewController, release it, and reconstruct in `viewDidLoad` that would be called when your view is loaded again (when user navigates back to this controller). You can inform your model classes to free memory too.

Problem

What should I do when my app recieves a memory warning?

Original source