Search code examples
iphonebackground-processuiapplicationdelegate

What causes apps to crash on resume after a long time in background?


I'm finding that after my app has been in the background for a while, (half hour + maybe) it crashes immediately on resume.

Crash log reveals that it is EXC_BAD_ACCESS, but I'm at loss for how to debug this one, because I don't know what gets released when my app goes to background (for a long time in particular). (Exception codes are 0x0000000 repeated)

Is there any documentation on this / can anyone give insight about what they did to fix this in the past?

While we're at it, is there a way to test this without waiting for hours before each try? Some way to simulate whatever it is that is happening to my app?

Thanks

Update

I just read a bit more closely, and there's something here about a timer, I added some stuff that uses timers recently to my app, could this give more info? (See item 12)

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x32858a1c __pthread_kill + 8
1   libsystem_c.dylib               0x337013b4 pthread_kill + 52
2   libsystem_c.dylib               0x336f9bf8 abort + 72
3   libstdc++.6.dylib               0x30504a64 __gnu_cxx::__verbose_terminate_handler() + 376
4   libobjc.A.dylib                 0x3068f06c _objc_terminate + 104
5   libstdc++.6.dylib               0x30502e36 __cxxabiv1::__terminate(void (*)()) + 46
6   libstdc++.6.dylib               0x30502e8a std::terminate() + 10
7   libstdc++.6.dylib               0x30502f5a __cxa_throw + 78
8   libobjc.A.dylib                 0x3068dc84 objc_exception_throw + 64
9   MarsCrash                       0x0000be88 0x1000 + 44680
10  MarsCrash                       0x00020646 0x1000 + 128582
11  Foundation                      0x327196ce __NSFireDelayedPerform + 362
12  CoreFoundation                  0x334e7a40 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
13  CoreFoundation                  0x334e9ec4 __CFRunLoopDoTimer + 844
14  CoreFoundation                  0x334ea83e __CFRunLoopRun + 1082
15  CoreFoundation                  0x3347aebc CFRunLoopRunSpecific + 224
16  CoreFoundation                  0x3347adc4 CFRunLoopRunInMode + 52
17  GraphicsServices                0x311a5418 GSEventRunModal + 108
18  GraphicsServices                0x311a54c4 GSEventRun + 56
19  UIKit                           0x31b90d62 -[UIApplication _run] + 398
20  UIKit                           0x31b8e800 UIApplicationMain + 664
21  MarsCrash                       0x00002558 0x1000 + 5464
22  MarsCrash                       0x00002500 0x1000 + 5376

Solution

  • Common case for such situations is a call to an object that was released due to low memory warnings. EXEC_BAD_ACCESS — accessing to over-release object according to Apple's source (http://developer.apple.com/library/mac/#qa/qa1367/) You can find an actual source of the problem by taking a crash logs from your device and symbolizing it to an actual code strings in your product. I assume that knowing the class and method and code line number will give you a preliminary understanding what goes wrong in your code. Please, review following apple's article to understand further details — http://developer.apple.com/library/ios/#technotes/tn2151/_index.html

    For an advanced topics on debugging following link maybe also very useful — http://developer.apple.com/library/ios/#technotes/tn2239/_index.html Actually Apple provides a ton of difference ways to debug such type of an issue.