I have a iPhone 3.0 application that is using core data in an
NSOperation to perform some updates.  It is using it's own
NSManagedObjectContext connected to a common (with the main thread)
persistent store coordinator.  Everything works great until the
NSOperation ends and is releasing the managed object context.  I get
an EXC_BAD_ACCESS on the operation thread.  Here is the trace:

#0      0x91a3c688 in objc_msgSend
#1      0x0036c854 in -[_PFManagedObjectReferenceQueue
_processReferenceQueue:]
#2      0x003a7c40 in -[NSManagedObjectContext(_NSInternalAdditions)
_dispose:]
#3      0x0040c92d in _deallocateContextBackgroundThread
#4      0x0035f41c in minion_duties2
#5      0x96777155 in _pthread_start
#6      0x96777012 in thread_start

I've seen this happen for two reasons. First, the MOC was created on a different thread and passed off to an operation to run on another thread without any locking. This can catch people, since NSOperation's init method runs on the originating thread that allocates it, but main runs on the actual NSOperation thread. MOCs created on the main thread are assumed to be special, with additional integration into the application's main event loop. It's important not to pass main thread MOCs to background threads. We discourage that generally (MOCs should be used by the thread that creates them), but it is possible for the background thread to call -lock to assume ownership.

The second more prosaic issue is simply an overreleased NSManagedObject. Instruments ObjectAlloc tool should be able to help you.

- Ben

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to