0

I thought my app was almost ready to ship, but this one thing is making me crazy!

In my didEnterBackground handler, I save some images to cache and dump everything I can possibly think of and the OS seems to randomly dump my app and restart it. It doesn't seem to be very consistent. Sometimes it comes back fine and sometimes I get a restart. According to Allocations, my memory usage is down to around 1 or 2 mb in my didEnterBackground.

And by dumping everything, I mean I remove subviews, remove objects from arrays and set a ton of stuff to nil...which means in my willEnterForeground I have to recreate a bunch of stuff.

I really don't know what else to do.

Any help here would be greatly appreciated. Thanks!

BTW, this is in iOS 5 and using ARC.

pizzafilms
  • 3,829
  • 4
  • 24
  • 39
  • 1
    Once in the background, your app can be terminated at any time. It's not clear from your question (the title says willEnterForeground, the question says didEnterBackground) where you are having the problem - you should expect that sometimes, when "returning" to your app, you are actually restarting it. – jrturton Feb 09 '12 at 07:03
  • Sorry about the title/question confusion, but I meant that my app goes into the background peacefully and releasing as much memory as possible, but **sometimes** when I tap the app to come back, it restarts instead of coming back where I left off. And I can't figure out why. – pizzafilms Feb 09 '12 at 15:15
  • That's expected behaviour. Doesn't matter if you're only using 1k, you can't guarantee you won't get killed off once in the background. Marius' answer below is correct. – jrturton Feb 09 '12 at 16:02

1 Answers1

2

At the background state the app can always get killed by the watchdog. There is no guarantee that the app is always working in the background.

To learn more about Multitasking watch the Session 320 from WWDC 2011 there is a plenty of information about multitasking.

mariusLAN
  • 1,195
  • 1
  • 12
  • 26
  • Thanks for that video. I watched it and I was already doing pretty much everything mentioned, but I still sometimes restart. What's really frustrating is that very few other apps seem to restart as often as mine. And sometimes my app restarts even when I've just displayed only a toolbar. Maybe some magic "don't kill me, I'm a good guy" flag? – pizzafilms Feb 10 '12 at 07:06
  • nope, you have to keep your memory low. thats all. the rest happens to the all mighty watchdog – mariusLAN Feb 10 '12 at 09:47