1

I have an app where I have 5 sets of animations that I'm storing in an array. The animations get picked to play randomly after a button touch. This is all working perfectly, however I noticed a bug when I quit the app and reopen immediately, I'll see my main view, then it'll jump to my second view that has the animation in it. (This shouldn't happen since you have to tap the main view in order for it to modally swap in the second view. If I interact with it everything works for a few seconds, then it closes with no crash log.

I finally realized that some of the objects must not be getting released fast enough, since if I close the app and wait three seconds, then reopen, everything executes fine.

I didn't want to put down code to show as this is more of a brainstorming question. I'd love any insight that could point me the right way. I changed a lot of my code to get rid of convenience methods and have all my variables defined and then released in my dealloc.

Is there a way to truly tell the app to kill everything on quit? It's not set to run in the background so this is a bit odd. Thanks for your help I'm still new to this and learning!

Quintin
  • 95
  • 9

3 Answers3

3

Alright, after working on this all weekend and doing more research comparing a barebones version of my app to my prerelease version, I traced memory leaks to the Flurry Analytics api that I am using. Apparently I was suffering from the same issue as the post here: App hangs on restart with latest Flurry SDK and ios4 . I resolved this by setting these optional methods to false, since they take extra time to send data after the app terminates, and depending on the connection it takes a few seconds.

FlurryAnalytics.h

/*
 optional session settings that can be changed after start session
 */
+ (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose;    // default is YES
+ (void)setSessionReportsOnPauseEnabled:(BOOL)setSessionReportsOnPauseEnabled;  // default is YES

Hope this helps anyone else who experienced something similar to me!

Community
  • 1
  • 1
Quintin
  • 95
  • 9
  • Yep, Flurry will attempt to send its report on close/shutdown, and that will delay the shutdown of the app. Basically, if you have this feature set (or anything else that delays shutdown) you need to change the app to handle applicationWillEnterForeground in a way that will cleanly reset the app, even if you have ExitsOnSuspend set. – Hot Licks Sep 26 '11 at 02:33
2

All apps can enter the background by default. Normally they do not do anything there, but they stay there in a frozen state and when you open them again, your program does not restart, it just picks up where it left off.

Anything that's set as an animation delegate might not get released, since it's retained for that purpose until the animation completes.

You can add an applicationDidEnterBackground: method to your app delegate to get informed when your app is going into the background, but exactly what you need to do depends on the design of your app. You can also add applicationWillEnterForeground: to do anything you need to do differently when restarting, as opposed to newly starting.

You might be able to force your animations to complete by starting a new animation with duration 0.0 (or very short if for some reason you can't do that).

morningstar
  • 8,952
  • 6
  • 31
  • 42
2

If this happens only if your app goes to bkgnd and comes back AND you don't mind if the app restarts everytime it comes back then just put UIApplicationExitsOnSuspend in your app's plist. In all my cases where these and other bad things happen with apps going to and returning from bkgnd this helped.

While you might still see the app on the buttom when double tapping it is really stopped and will restart. Apps that show on the buttom do not always have to run or be stored in the bkgnd I learned.

ps. don't forget to set the value of UIApplicationExitsOnSuspend to YES

user387184
  • 10,953
  • 12
  • 77
  • 147
  • Thanks for the suggestion, I'm going to get to this after work and let you know how it went, thanks!! – Quintin Sep 21 '11 at 14:12
  • Thanks for your help, unfortunately that didn't work. I'm working with the applicationDidEnterBackground method recommended below to see how that goes. Thanks! – Quintin Sep 22 '11 at 06:18
  • Thanks for the update - please keep us posted - since I am surprised that your app does not quit as you say when sending it to bkgnd. I have not seen this before. Are you sure it really quits. When you restart, can you check somehow that it really restarts. Not that there is something wrong with the setting. Did you set the value for UIApplicationExitsOnSuspend to YES ? – user387184 Sep 22 '11 at 07:07
  • Yep I had it set to YES to Exit on Suspend. It was just the animations that seemed to get released 2-3 seconds after. However I decided to recode the app as I was building it as I went originally, and now I have a better idea of programming design. I resolved the problem by tightening up my methods keeping better track of what was released/autoreleased. Thanks to you and @morningstar for your help! – Quintin Sep 24 '11 at 20:38
  • I updated this issue with the correct answer! Thanks @user387184 for your help. – Quintin Sep 26 '11 at 02:19