views:

224

answers:

2

Hi there,

I've noticed I'm getting a few errors at random points in my app. I've had 2 errors, "double free" and "incorrect checksum for freed object". Heres the stack trace of a "double free" error. Can anyone provide any insight? It's happening on a call in my code that just sets an attribute to an NSNumber so I can't understand why it's doing it!

myObject.numberAttr = [NSNumber numberWithInt:[dateComponents day]];

Randomly Triggered (Doesn't always happen):

#0  0x9585b072 in malloc_error_break
#1  0x9585c218 in szone_error
#2  0x9585c34d in free_tiny_botch
#3  0x01c5e064 in _PFDeallocateObject
#4  0x01c97e2b in -[NSManagedObject(_NSInternalMethods) _setLastSnapshot__:]
#5  0x01c97a0d in -[NSManagedObjectContext(_NSInternalChangeProcessing) _establishEventSnapshotsForObject:]
#6  0x01c97866 in _PFFastMOCObjectWillChange
#7  0x01c976c5 in _PF_ManagedObject_WillChangeValueForKeyIndex
#8  0x01c97525 in _sharedIMPL_setvfk_core
#9  0x01c9b827 in _svfk_5

Many thanks,

Michael

+1  A: 

The "numberAttr" works like a property declared as retain, so when you change its value to reference a different NSNumber object, the previous NSNumber object will be sent a release message. I would expect to see this behavior if that previous object had already been released.

Do you have other places that you are setting "numberAttr"? Is it possible that one of those NSNumber objects has been released before you change the attribute here?

gerry3
A: 

I figured it out! It turns out that it was a threading issue with my managed object context. I was creating it on the main thread and using it on my background thread. However it would seem that the context has to be created and used all within 1 thread. Hope this helps anyone else who may come across this issue as the debugging information wasn't very clear!

Michael Waterfall