Core Data and Garbage Collection
Core Data and Garbage Collection
- Subject: Core Data and Garbage Collection
- From: Michael Link <email@hidden>
- Date: Tue, 9 Sep 2008 17:59:24 -0500
I'm running an application with the Core Data thread assertions on and
am running into some issues on the garbage collection thread.
On the GC thread (#2 usually in GDB), finalizeOneObject() is running
the finalize method of an NSTextValueBinder object. This object is
bound to the attribute of an NSManagedObject by way of a couple of
other objects. From the way the stack trace looks I assume that the
finalize method of NSTextValueBinder is undoing the observers and in
the process calls -valueForKey: on the MO (not on the main thread
where its managed object context lives) and this triggers an assertion
failure from the MOC.
During -finalize on the GC thread is it allowed to use the MOC from
the main thread (I wouldn't do this myself)? Or does the binding/
observers need to be undone before this reaches GC? I was under the
impression that observers would be cleaned up automatically.
The binding key path is:
representedObject.fromUser.name
representedObject is an NSManagedObject
fromUser is an NSManagedObject
name is an NSString attribute of fromUser
#0 0x90debbb4 in -[NSAssertionHandler
handleFailureInMethod:object:file:lineNumber:description:] ()
#1 0x0021d9af in -[NSManagedObjectContext(_NSInternalAdditions)
_PFAssertSafeMultiThreadedAccess_impl:] ()
#2 0x0015e995 in -[NSManagedObject valueForKey:] ()
#3 0x90d7afa1 in -[NSKeyValueNestedProperty
object:didRemoveObservance:] ()
#4 0x90d5a203 in -[NSObject(NSKeyValueObserverRegistration)
_removeObserver:forProperty:] ()
#5 0x90d59fa4 in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:] ()
#6 0x90d7afc1 in -[NSKeyValueNestedProperty
object:didRemoveObservance:] ()
#7 0x90d5a203 in -[NSObject(NSKeyValueObserverRegistration)
_removeObserver:forProperty:] ()
#8 0x90d59fa4 in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:] ()
#9 0x90207b74 in -[NSBinder _updateObservingRegistration:] ()
#10 0x9024e1ef in -[NSBinder
releaseConnectionWithSynchronizePeerBinders:] ()
#11 0x9024e3f5 in -[NSValueBinder
releaseConnectionWithSynchronizePeerBinders:] ()
#12 0x903f0ee0 in -[NSBinder finalize] ()
#13 0x91675976 in finalizeOneObject ()
#14 0x92d75dab in foreach_block_do ()
#15 0x91675b3b in batchFinalize ()
#16 0x91675e02 in batchFinalizeOnTwoThreads ()
#17 0x92d76f0e in auto_collect_internal ()
#18 0x92d77b8f in auto_collection_thread ()
#19 0x93f8c6f5 in _pthread_start ()
#20 0x93f8c5b2 in thread_start ()
(gdb) info frame
Stack level 2, frame at 0xb01025f0:
eip = 0x15e995 in -[NSManagedObject valueForKey:]; saved eip
0x90d7afa1
called by frame at 0xb01026c0, caller of frame at 0xb0102590
Arglist at 0xb01025e8, args:
Locals at 0xb01025e8, Previous frame's sp is 0xb01025f0
Saved registers:
ebx at 0xb01025e0, ebp at 0xb01025e8, esi at 0xb01025e4, eip at
0xb01025ec
(gdb) po *(int*)(0xb01025e8 + 16)
fromUser
(gdb) info frame
Stack level 13, frame at 0xb0102c60:
eip = 0x91675976 in finalizeOneObject; saved eip 0x92d75dab
called by frame at 0xb0102c90, caller of frame at 0xb0102c40
Arglist at 0xb0102c58, args:
Locals at 0xb0102c58, Previous frame's sp is 0xb0102c60
Saved registers:
ebp at 0xb0102c58, eip at 0xb0102c5c
(gdb) po *(int*)(0xb0102c58 + 8)
<NSTextValueBinder: 0x2eb6b90>{object: (null), bindings:
value=representedObject.fromUser.name}
(gdb) c
Continuing.
2008-09-09 17:47:06.883 Spyder[1140:2903] *** Assertion failure in -
[NSManagedObjectContext _PFAssertSafeMultiThreadedAccess_impl:], /
SourceCache/Persistence/Persistence-186/NSManagedObjectContext.m:2340
objc[1140]: GC: -finalize resulted in an exception (0x2ec4600) being
thrown, break on objc_exception_during_finalize_error to debug
CoreData: warning: Access by another thread to NSManagedObjectContext
during valueForKey:
--
Michael
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden