0

Hey all basically I'm trying to save an array of custom objects, it saves fine but when I close the app and reopen it actually loads the saved array (into a table view) but freezes up and all I get is SIGKILL. How do I find what's causing the issue?

This is the code I'm using to load the data if it helps:

NSFileManager *fileManager = [NSFileManager defaultManager];

     if([fileManager fileExistsAtPath:dataFilePath]) {
         // Load the array
         NSMutableArray *arrayFromDisk = [NSKeyedUnarchiver
                                          unarchiveObjectWithFile:dataFilePath];

         [Data sharedData].listOfItems = arrayFromDisk;

         NSLog(@"Loaded");
     }
Adam Ashwal
  • 1,472
  • 1
  • 19
  • 36
  • Have you looked at [this question](http://stackoverflow.com/questions/3098684/iphone-app-running-simulator-4-0-received-sigkill)? – jtbandes Aug 17 '11 at 17:07
  • @jtbandes I am saving all my data in `- (void)applicationDidEnterBackground:` and the problem is that I'm getting a sigkill when I reopen the app again. – Adam Ashwal Aug 17 '11 at 17:12

2 Answers2

1

Setting the following breakpoints might help:

  • objc_exception_throw
  • malloc_error_break
  • [NSException raise]

Check this thread for xCode 4 https://devforums.apple.com/thread/68421

on xCode 3 http://blog.emmerinc.be/index.php/2009/03/19/break-on-exception-in-xcode/

Hope this helps

Lio
  • 4,225
  • 4
  • 33
  • 40
  • I followed your link and added the breakpoints, I'm trying to learn so bear with me, but what exactly am I looking for? – Adam Ashwal Aug 17 '11 at 18:45
  • You should try to reproduce the same error, the idea is to break when the error occurs. This way you will know where the bug is, or at least have a better idea of where it might come from. – Lio Aug 17 '11 at 18:58
  • ok, I'm still getting the error. though the console does say `Re-enabling shared library breakpoint 1 Re-enabling shared library breakpoint 3 Pending breakpoint 2 - "malloc_error_break" resolved` if that matters... – Adam Ashwal Aug 17 '11 at 19:08
  • Did you take a look at the debugger contents then? Can you print a backtrace?(enter bt on the console while the app is paused) – Lio Aug 17 '11 at 19:12
  • This is what it prints when the app freezes:`#0 0x307cdcb8 in mach_msg_trap () #1 0x307cd4f0 in mach_msg () #2 0x36c5c89a in __CFRunLoopServiceMachPort () #3 0x36c5b370 in __CFRunLoopRun () #4 0x36bfd03c in CFRunLoopRunSpecific () #5 0x36bfcf04 in CFRunLoopRunInMode () #6 0x3071b0d4 in GSEventRunModal () #7 0x31fc9990 in UIApplicationMain () #8 0x00002e34 in main (argc=1, argv=0x2fdffbb0) at` – Adam Ashwal Aug 17 '11 at 19:14
0

It sounds like your code may be throwing an exception, which would be most likely to happen at unarchiveObjectWithFile:. The normal behavior is to log the exception and stacktrace to the console (so look there), but you could also try wrapping the call in @try ... @catch to see if in fact an exception is being thrown:

@try {
    // Load the array
    NSMutableArray *arrayFromDisk = [NSKeyedUnarchiver
                                      unarchiveObjectWithFile:dataFilePath];

    [Data sharedData].listOfItems = arrayFromDisk;

    NSLog(@"Loaded");       
}

@catch (NSException* e) {
    NSLog(@"Caught exception: %@", e);
}
bosmacs
  • 7,341
  • 4
  • 31
  • 31
  • sorry I'm still new to this, how would I log the exception and stacktrace? (I know NSLOG, just what exactly am I logging out?) – Adam Ashwal Aug 17 '11 at 18:26
  • Then the problem doesn't appear to be with the code above. Have you used the debugger to see at what point your application is terminated, or looked at the console to see if any error messages are being output? – bosmacs Aug 17 '11 at 18:31
  • Looking at the console I get don't see an error, I don't mean to be a pain, just trying to learn, but how do I get that up in the debugger ? – Adam Ashwal Aug 17 '11 at 18:44
  • Are you storing/restoring a large number of objects? If you are unarchiving them on the main thread when your app starts up, and it takes too long, you'll get a SIGKILL. From the [iOS dev guide](http://developer.apple.com/library/iOS/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Performance/Performance.html): "During these times, your application is expected to respond to events in a timely manner. If your application’s main thread is blocked at launch time, the system could kill the application before it even finishes launching." – bosmacs Aug 17 '11 at 18:49
  • It's 3 objects with 2 NSString properties and a BOOL property. I would imagine that's not an issue. (the strings are very short, a couple of words max) – Adam Ashwal Aug 17 '11 at 18:56
  • Yeah, I wouldn't think hat would be the problem then. Probably best to pursue @Lio's line and try to isolate exactly the point where your program is killed. – bosmacs Aug 17 '11 at 20:14
  • It turns out it's an issue with the debugging process still running. Once I hit stop in Xcode it works perfectly fine. Thanks for the help – Adam Ashwal Aug 18 '11 at 18:41
  • In addition to logging the exception, log the stack trace with `NSLog(@"Stack trace: %@", [exception callStackSymbols]);` – Hot Licks Jan 14 '13 at 17:48