2

I am running my application on iOS 7.0.1 & iPod Touch 5th generation device. When I follow below steps my app quits with below error on Xcode 5 without any error in console

App quit Unexpectedly Terminated due to Memory Pressure

Steps: 1) Run my application using Xcode 5. Login & then go to Home

2) Click on Home button so that my app enters in background (I can see my app is in background)

3) Start inbuilt Photos app from iOS. Click 1 or 2 pictures

4) After taking 1-2 pictures , App quit Unexpectedly Terminated due to Memory Pressure

I am not doing anything in my app. When I checked the CPU usage its 0% & Memeory used = 15.2 MB Also there is no other app running in the background except my app.

Can anybody help with this ? Thanks

I am not getting why this is happening. If I don't use Photos.app then app works smoothly.

iOSAppDev
  • 2,755
  • 4
  • 39
  • 77
  • When your app is not doing anything, iOS will kill it as soon as the user does something resource intensive. If your app is doing something, then your app is less likely to be killed. But it still might happen. – Abhi Beckert Dec 26 '13 at 09:46

1 Answers1

7

There's nothing you can, or should, do about this. You application is no longer in the foreground, and the foreground app (photos) is asking for more memory. To supply this, iOS will terminate any apps running in the background. It doesn't matter how much memory your app is using, iOS will terminate background apps as long as the foreground app requires more memory.

Once your app enters the background you can expect it to be terminated at any time. To improve the user experience, you can look at Enabling State Preservation and Restoration in Your App. This in theory allows your app to start where it left off when the user comes back to it.

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
jrturton
  • 118,105
  • 32
  • 252
  • 268
  • 1
    Remember iOS doesn't randomly choose which background apps to terminate. It's based on what those apps are doing at the moment. If the app is doing something (eg: receiving GPS updates) and only using 15MB it probably would not be killed, unless the foreground app *really* needs 100% of the resources. – Abhi Beckert Dec 26 '13 at 09:48
  • 1
    True, but the OP said his was the only app running. And the photos app is a bit of a hog... – jrturton Dec 26 '13 at 09:52
  • @jrturton Thanks for your answer. I have idle timeout implemented in my app. I can't use state restoration as whenever my app launched , I need to ask for login due to security reasons as per project requirement. For now whats happening is my app gets killed due to Photos app & next time app asks for login. So testers are thinking that idle timeout is not working correctly. – iOSAppDev Dec 26 '13 at 11:18
  • You could always store the time the user went into the background, and auto-log in if the next launch time is soon enough. Depends on the nature of the rest of your app. – jrturton Dec 26 '13 at 12:42