Re: Crashing resetting or releasing an NSManagedObjectContext
Re: Crashing resetting or releasing an NSManagedObjectContext
- Subject: Re: Crashing resetting or releasing an NSManagedObjectContext
- From: Alexander Spohr <email@hidden>
- Date: Mon, 4 May 2009 19:59:01 +0200
You are still having the same error.
All your objects in the relationships are fetched. Therefore they are
owned by the NSManagedObjectContext. You kill the
NSManagedObjectContext by releasing it. After that point you are not
allowed to touch any of its fetched objects. But you hand them out
inside the NSDictionary.
Pleas reconsider my first tip and let the calling method create the
NSManagedObjectContext. Use that to fetch all your objects, process
them and _then_ kill your NSManagedObjectContext.
An NSManagedObject can not live without its NSManagedObjectContext.
The NSManagedObjectContext ist the bucket that holds it. You can not
take it out and throw the bucket away. Will not work.
atze
Am 01.05.2009 um 10:24 schrieb Daniel Kennett:
NSManagedObjectContext *context = [[NSManagedObjectContext alloc]
init];
Pet *pet = [KNClarusQuickDocumentParser petAtURL:url
inContext:context];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[[[pet valueForKey:@"name"] copy] autorelease]
forKey:@"name"];
[dict setValue:[[[pet valueForKey:@"birthday"] copy] autorelease]
forKey:@"birthday"];
// More copying of strings and dates
[..]
[dict setValue:[[[pet valueForKey:@"pertinentActions"] copy]
autorelease] forKey:@"pertinentActions"]; // <--- Here
[context release];
^^^^^^^^^^^^^^^^^ this release kills all fetched objects.
return [dict autorelease];
^^^^^^^^^^^^^^^^^ this dict contains dead objects.
_______________________________________________
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