Debugging Core Data

13 Mar
2010

Lesson learned after hours of debugging:

never never never ever use core data objects _after_you saved the context (without explicit retaining them)

They don’t even turn to Zombies. The App just dies hard. something like SIGSEGV — SEGV_ACCERR.
And the stack trace wasn’t helpful at all. F**k you, NXHashRemove.

My code looked somthing like this:

  User *user = msg.user;
  [_context deleteObject:msg];  
  [self saveCurrentContext];
  [user updateCachedMessageAttributes];

to fix the crashes, just move the save to bottom.

  User *user = msg.user;
  [_context deleteObject:msg];  
  [user updateCachedMessageAttributes];
  [self saveCurrentContext];

User gets invalidated after saving. Another way to fix it is to manually retain the object, save, and then release it.

Related posts:

  1. Multithreading with Core Data
  2. Core Data Notes from iPhone Tech Talk
  3. CoreData and mergeChangesFromContextDidSaveNotification

Comment Form

top

Switch to our mobile site