Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mpramodjain

macrumors regular
Original poster
Nov 20, 2008
152
0
Banglore
Im curious as to what happens when an app crashed. Do any of the dealloc methods run? Is every memory allocation auto released that has to do with the application that crashed? Anybody know?


I am just in the googling this.. and found following

crashbucket - iPhone crash tracking
https://github.com/kaler/CrashKit

Wonder how they achieved.. They do the same.. when an app crash, the crash report gets hit their server . .. If u find any thought around their implementation.. please share.. it seems an interesting to know.. these kind things..
 
Im curious as to what happens when an app crashed. Do any of the dealloc methods run?

This is something that is very easily tested :)

Instrument your application delegate, and create a crash by dereferencing invalid memory.

Code:
#define HERE() NSLog(@"%s, %u: %s", __FILE__, __LINE__, __FUNCTION__)

- (void) applicationWillTerminate:(UIApplication*)app {
    HERE();
    // ...
}

- (void)dealloc {
    HERE();
    [super dealloc];
}

- (void)crash {
    HERE();
    char* segv = 0;
    *segv = 42;
}

See also documentation for the dealloc method: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html

Apple iOS Developer Library said:
When an application terminates, objects may not be sent a dealloc message. Because the process’s memory is automatically cleared on exit, it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management methods.
 
If an app crashes, under any operating system, typically no user clean up code is called. A crash is catastrophic, and the app is presumed to be in a bad state. Calling any user code in such a state is likely to just cause more crashes. So typically operating system just terminates the process. As part of terminating a process, any system resources owned by the process (memory, for example) is freed.
 
You are ignoring any operating system which provides user exception handling through various interrupt intercept handlers.

But that's not a crash. A crash is when an application doesn't/can't handle the exception. That's like putting a top-level try/catch in my main, thereby having an orderly exit on an unhandled exception. In that case, at the operating system level, it's a normal exit even though to the user it may not be.

LOL. Which leads should lead the OP to his answer. :)
 
Last edited:
OK, semantics. I was simply commenting on your statement that "... no user code is called...". If the app is handling exceptions, than the code IS called, but then no CRASH occurs. Chicken/egg?
 
crashbucket - iPhone crash tracking
https://github.com/kaler/CrashKit

Wonder how they achieved.. They do the same.. when an app crash, the crash report gets hit their server . .. If u find any thought around their implementation.. please share.. it seems an interesting to know.. these kind things..

On that page, under README, is this:
CrashKit catches uncaught exceptions, traps signals, and sends them to developers by email or straight to your bug database. More info at this blog post, CrashKit: Helping Your iOS/iPhone Apps Suck Less.
The blog post explains what CrashKit does, and how it does it. For implementation details, you already have the link to the source.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.