views:

2782

answers:

2

Regarding the black art of managing memory on iPhone OS devices: what do the different levels of memory warning mean. Level 1? Level 2? Does the dial go to 11?

Context: After an extensive memory stress testing period - including running my iPad app with the iPod music player app playing, I am inclined to ignore the random yet infrequent memory warnings I am receiving. My app never crashes. Ever. My app is leak free. And, well, the mems warnings just don't seem to matter.

Thanks,
Doug

+7  A: 

Basically the warnings mean that the device is running low on memory, and that, "If you could please free some memory you aren't actively using that'd be swell!". If your memory management is tight, and you have no objects that could practically be discarded, just pass the message along and ignore it.

Williham Totland
LOL "If you could please free some memory you aren't actively using that'd be swell!" Priceless ;-) Cheers
dugla
You sound like a grissled veteran of the iPhone OS wack-a-mole memory dance.
dugla
+18  A: 

Memory level warnings are logged by SpringBoard. As an app developer you don't need to care about it. Just responding to -{application}didReceiveMemoryWarning is enough.


There are 4 levels of warnings (0 to 3). These are set from the kernel memory watcher, and can be obtained by the not-so-public function OSMemoryNotificationCurrentLevel().

typedef enum {
    OSMemoryNotificationLevelAny      = -1,
    OSMemoryNotificationLevelNormal   =  0,
    OSMemoryNotificationLevelWarning  =  1,
    OSMemoryNotificationLevelUrgent   =  2,
    OSMemoryNotificationLevelCritical =  3
} OSMemoryNotificationLevel;

How the levels are triggered is not documented. SpringBoard is configured to do the following in each memory level:

  1. Warning (not-normal) — Relaunch, or delay auto relaunch of nonessential background apps e.g. Mail.
  2. Urgent — Quit all background apps, e.g. Safari and iPod.
  3. Critical and beyond — The kernel will take over, probably killing SpringBoard or even reboot.

Killing the active app (jetsam) is not handled by SpringBoard, but launchd.

KennyTM
Thanks for this. It was a toss between you and Williham the comedian on this question. Humor wins. Cheers.
dugla
Hi,I have same issue. After running the application continuously ffor more than 5 times, I am getting Received memory warning. Level=1 for 20 times, but application is not crashing.But when I get this message, Received memory warning. Level=2 my application is crashing.Level2 is appearing after Level1 appearing for nearly 20 times. How can I make my application not to crash.Thank you
srikanth rongali
@srik: Use less memory.
KennyTM
@Kenny: Less memory means , how much can we use maximum. How much can we have live bytes. In my crash log I got this.Free pages: 371 Wired pages: 12192 Purgeable pages: 0 Largest process: DTMobileIS What this mean ? Where I should take care ?Thank You.
srikanth rongali
@srik: You'd better [ask a new question](http://stackoverflow.com/questions/ask).
KennyTM
Thanks for actually answering the OP. Very informative.
mtc06

related questions