What should I do when my application receives a memory warning?

What if my application receives a memory warning?

+6
memory-management memory iphone ipad
source share
4 answers

It all depends on your application, usually you do not need to do anything other than the recommendations recommended by Apple.

ViewControllers that are not currently displayed will receive a didReceiveMemoryWarning message. By default (calling [super didReceiveMemoryWarning] ), the view of the controller is unloaded (freed, freed). When the view is unloaded, the view controller receives viewDidUnload , where you must release all of your IBOutlets (or otherwise saved user interface elements). Only then can performance be completely free and memory free.

In didReceiveMemoryWarning you should also free up as much data as possible - if you save some part of the data model in the ViewController, release it and restore it to viewDidLoad , which will be called when your view is loaded again (when the user navigates to this controller). You can also tell your model classes about free memory.

+8
source share

It really depends on your application.

If your application downloads and caches a large amount of content from the Internet, for example, you should clear as much as possible when you receive a warning.

If your application is an OpenGL game, you may have a texture / sound / data manager that refers to some unused data that you want to free. Cocos2D manages these things.

If your application is not memory intensive, you have a memory leak somewhere and you must: 1) read the Apple Memory Management Programming Guide; 2) use tools / leaks.

+1
source share

In didReceiveMemoryWarning you must free any cached or non-essential items so that you don't run out of memory completely.

0
source share

If you register or write to any other file, there may be a problem with disk space.

You should also check for memory leaks.

-one
source share

All Articles