Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do when my app receives memory warning?

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

like image 744
Omer Avatar asked Oct 26 '10 12:10

Omer


People also ask

How to handle memory warning in iOS?

Remove references to any temporary objects that you no longer need. If active tasks might consume significant amounts of memory, pause dispatch queues or restrict the number of simultaneous operations that your app performs. Failure to reduce your app's memory usage may result in your app's termination.

What is memory warning?

onLowMemory() raises when the system global memory is low. If the global memory is okay but your process takes more than 24MB on old Android devices, it will crash and you'll never get a low memory warning.

How do I reduce memory usage on my IPAD?

Delete Them On that device storage page, look for apps you don't use. Tap them and select Delete App. Any purchased app is always available to re-download again at no extra charge from the App Store. To delete apps from the home screen, place your finger on an app you want to delete and hold.


2 Answers

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.

like image 190
Michal Avatar answered Oct 21 '22 15:10

Michal


It really depends on your app.

If your app downloads and caches lots of contents from Internet for example, you should purge as much as possible when receiving a warning.

If your app is an OpenGL game, you might have a texture/sound/data manager which references some unused data, which you then want to free. Cocos2D manages this kind of things.

If your app isn't memory intensive, you have a memory leak somewhere, and you should 1) read the Memory Management Programming Guide by Apple 2) use Instruments/Leaks.

like image 36
jv42 Avatar answered Oct 21 '22 15:10

jv42