• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
re: Core Data Crash on MOC Release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: Core Data Crash on MOC Release


  • Subject: re: Core Data Crash on MOC Release
  • From: Ben Trumbull <email@hidden>
  • Date: Thu, 13 Aug 2009 10:49:11 -0700

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 (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


  • Prev by Date: Re: Trouble with NSColor
  • Next by Date: Re: Trouble with NSColor
  • Previous by thread: Re: Core Data Crash on MOC Release
  • Next by thread: Arbitrary length ints from NSData
  • Index(es):
    • Date
    • Thread