re: Trouble with core data and Save As
re: Trouble with core data and Save As
- Subject: re: Trouble with core data and Save As
- From: Ben Trumbull <email@hidden>
- Date: Tue, 2 Mar 2010 13:31:09 -0800
> I'm having another look at an issue I posted about a couple of weeks ago, where Save As was causing an error. At the time, I was using a custom managed object context. I have now reverted to a standard managed object context. I do not create or release this managed object context anywhere - it gets automatically created when I first access it from my persistent document...but this context is not where the problem occurs.
>
> When I do a Save As, it migrates to a new store behind the scenes, it appears to load my objects into the new store OK, and accesses the attributes OK, but then I get a crash where it tries to send a message to a deallocated NSManagedObjectContext. This context is created by core data internally as Instruments shows:
>
> # Category Event Type RefCt Timestamp Address Size Responsible Library Responsible Caller
> 0 NSManagedObjectContext Malloc 1 00:28.911 0x11d0d58a0 240 CoreData -[NSPersistentStoreCoordinator(_NSInternalMethods) _retainedAllMigratedObjectsInStore:toStore:]
> 1 NSManagedObjectContext Autorelease 00:28.953 0x11d0d58a0 0 CoreData -[NSPersistentStoreCoordinator(_NSInternalMethods) _retainedAllMigratedObjectsInStore:toStore:]
> 2 NSManagedObjectContext Zombie -1 00:28.955 0x11d0d58a0 0 CoreData -[NSManagedObjectContext(_NSInternalAdditions) _dispose:]
>
> As far as I can see, I never get a look in. It all appears to be triggered by [NSPersistentStoreCoordinator migratePersistentStore:toURL:options:withType:error:].
Instruments can get confused by custom -retain / -release methods, so those may not be all the events.
> But obviously there must be something somewhere in my code causing this problem.
>
> I am just totally clueless as to where to look, and would appreciate any suggestions.
>
> I thought there might be something happening in one of my awake... methods or a dealloc or willTurnIntoFault or didTurnIntoFault, but I didn't find anything that looked suspicious. The store is an NSAtomicStore subclass, and I read that there could be problems with Save As if newReferenceObjectForManagedObject: did not return a constant value, but that isn't called before it crashes...so I'm stuck.
>
> Any ideas?
The custom store seems like the most probable source of issues. One source of problems I've seen is when a custom store doesn't handle either the metadata or the objectIDs correctly. The store UUID and the object's IDs need to be stable (e.g. if we ask your store for its UUID, it doesn't make up a new answer for every question). If you give us an objectID to assign to an object, you cannot later change your mind. And then there's just not preserving the contents of the metadata.
If you can create a stripped down sample project that reproduces the issue, you could file a bug.
- 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