views:

52

answers:

2

Are there any specific guidelines of what to do if you get a memory warning? I know that you have to try and kill off objects that aren't required, but if this makes your application inoperable, what other options are there?

An example might be if say the application was Apple's contacts app and the user is editing a person's contact details. What could you do? Stop the edit? close down and jump to the list screen?

Any advice or guidelines would be most appreciated.

+1  A: 

If your app is in the foreground and needs all the memory it has currently allocated to present a good user experience, then a perfectly reasonable option is to do nothing after getting a memory warning, and hope the OS kills or memory starves some other process.

But it might be a good idea to at least save important state in case your app isn't so lucky.

hotpaw2
Thanks, that makes sense to me...but is this acceptable to Apple?
WaterBoy
The only way to find out what is acceptable to Apple is to submit an app for review. But there are apps in the App store that simply ignore memory warnings.
hotpaw2
+2  A: 

they will not specify how much you need to free... you just destroy things you're able to rebuild (e.g. those which are offscreen). don't steal/destroy what the user is looking at. ultimately, the system may just terminate your app if it needs the resources. i just take the approach: if offscreen, purge medium+large allocs which can be rebuilt when the user navigates back to that screen, and try to keep your memory consumption low to begin with - measure how much you use in test runs.

Justin