Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing app from active tasks results in crash when trying to reopen the app

I find I can crash my iOS app by performing the following:

  1. Start the app
  2. Exit the app (using the home button)
  3. Double-click the home button to bring up the running task list
  4. Force my app to close
  5. Close the task list
  6. Start my app (crash)

So far:

  • This only happens on the device (3GS running 4.3.1) when I'm running the debugger
  • I can't make it happen with other apps
  • It doesn't happen every time I do this
  • It leaves the iPhone in an ambiguous state with a black screen - ending the process in xcode doesn't push me back to springboard, pressing the home button has no effect. I press the power button, then the home button and it goes back to springboard.

I'm doing this very quickly, though, so I'm curious if it's likely to be a bug in my app (and what the bug could be) or if springboard is killing my app just as I'm restarting it?

The debugger reports that my app received the signal "SIGKILL" so I'm inclined to believe it's just a delay in actually killing the process, but I don't want to overlook a mistake I might have made.

Given that I can't repeat it outside the debugger it's low priority for me, but I'd still like to understand it better if possible, especially if it points to an error in my app.

like image 331
Adam Davis Avatar asked Apr 05 '11 19:04

Adam Davis


People also ask

Why is my app closing as soon as I open it?

Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.

What causes apps to crash on iPhone?

Causes of iPhone App CrashLow device memory. Network issues. Device incompatibility problems. Software issues such as outdated software.


1 Answers

When you kill your app, the OS sends it SIGKILL. Normally this kills your app, but since there's a debugger attached, the app is suspended instead to give you a chance to debug the cause of the signal (there probably ought to be an exception for SIGKILL, but it's not a big problem that there isn't one).

When you launch it again, SpringBoard (the home screen) notices that the app isn't dead and switches to it. [1] At this point, there's nothing it can do since the app is suspended. I think SpringBoard handles an unresponsive app by sending it SIGKILL and waiting for the app to die, but GDB's still attached, your app's still suspended, and nothing happens.

At this point I usually click Xcode's stop button, or if that doesn't work (because Xcode 4 is a buggy POC) unplug the phone.

And if you're wondering why SpringBoard doesn't simply ignore the old instance of your app and spawn a new one: There Can Only Be One Instance Running. Apps make that assumption all the time (e.g. there isn't another instance of your app accessing its database), and I'm pretty sure there's something about Mach ports/bootstrap namespaces/something that means your app won't launch if there's another copy running (or if a part of the system thinks your app is still running because something failed to do cleanup).


On an older OS version, if your app spent a lot of time doing something at exit (e.g. saving), exiting and quickly "re-launching" the app would switch to the in-the-process-of-exiting app, and the app would finish exiting, and the home screen would suddenly appear. I forget which OS version I saw this in, but I think it's fixed.

like image 116
tc. Avatar answered Oct 15 '22 19:10

tc.