Why does your app crash when the device is low on memory in iPhone ?


Every developer knows that iOS will terminate your application if the device is low on memory.  Not all of them know or even think about why that is.  The answer can be quite deep, depending on the candidate.  First, you need to understand that iOS devices use virtual memory with paging, but unlike desktop systems there is no backing store (no hard drive essentially) so there is a limit to the number of pages available.  This environment then leads to conditions where some apps, such as safari or itunes, can be using many pages even when they are not active, the pages they are using take away from the pages your app is allowed to use.  This means that even if your app only allocates a couple megabytes on launch, it may still crash if no other apps release their pages — your allocations will fail.  The OS tries to give priority to the active application by terminating background apps, but if you are allocating a large buffer (such as a photo) or quickly allocating small buffers, the OS might not be able to free up pages quickly enough.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s