Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone OS Memory Warnings. What Do The Different Levels Mean?

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

like image 402
dugla Avatar asked May 26 '10 17:05

dugla


People also ask

What does it mean if my iPhone is low on memory?

Low memory issues can arise when you have too many apps installed on your device. Another factor that can cause the same problem to arise on your iPhone is your cache. Your apps accumulate a lot of cache, especially if they don't have self-cleaning functions.

What is iOS memory?

Advertisements. Memory management in iOS was initially non-ARC (Automatic Reference Counting), where we have to retain and release the objects. Now, it supports ARC and we don't have to retain and release the objects. Xcode takes care of the job automatically in compile time.

How much memory can iOS app use?

Beta versions of iOS 15 and iPadOS 15 now give developers the option of requesting more RAM than the current 5GB maximum per app, with limitations. Apple has always set a cap on how much RAM any one app can use on the iPad, but it's become more of an issue as the devices themselves physically include more.


1 Answers

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.

like image 159
kennytm Avatar answered Sep 16 '22 20:09

kennytm