What happens when app crashes in iOS

Discussion in 'iOS Programming' started by mpramodjain, Sep 16, 2011.

  1. mpramodjain macrumors regular

    Joined:
    Nov 20, 2008
    Location:
    Banglore
    #1
    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..
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    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

     
  3. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #3
    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.
     
  4. CalWizrd Suspended

    CalWizrd

    Joined:
    Jun 21, 2011
    Location:
    NYC/Raleigh, NC
    #4
    You are ignoring any operating system which provides user exception handling through various interrupt intercept handlers.
     
  5. jiminaus, Sep 16, 2011
    Last edited: Sep 16, 2011

    jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #5
    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. :)
     
  6. CalWizrd Suspended

    CalWizrd

    Joined:
    Jun 21, 2011
    Location:
    NYC/Raleigh, NC
    #6
    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?
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    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.
     

Share This Page