Re: Crashing resetting or releasing an NSManagedObjectContext
Re: Crashing resetting or releasing an NSManagedObjectContext
- Subject: Re: Crashing resetting or releasing an NSManagedObjectContext
- From: Keary Suska <email@hidden>
- Date: Wed, 29 Apr 2009 09:10:41 -0600
On Apr 29, 2009, at 2:59 AM, Daniel Kennett wrote:
Different combinations of trying to do this right result in crashes
at different points. Leaving out [context reset] and just releasing
it obviously gives EXC_BAD_ACCESS again. Autoreleasing the MOC in
+petAtURL: causes crashes when the autorelease pool pops. The only
way I can get it to not crash is to -init the MOC and never release
or autorelease it, but that's causing memory leaks!
The most common cause if this error is an over-release. Turn on
zombies and see who (if any) is being over-released. The culprit could
be in your "copy data" code, that you don't provide. There doesn't
seem to be anything obviously wrong (other than explained below), that
I can see.
Is there a good example anywhere of how to set up and tear down a
Core Data document correctly?
I can say that the design you present is flawed according to OOP
rules, specifically how you release the managed object context. An
object should never release an object it doesn't own or has retained.
I understand why you are doing this--I am just saying it is a flawed
approach.
I don't know what the KNClarusQuickDocumentParser class does in its
entirety, but it may call for a singleton pattern or at least a shared
object pattern (not a proper pattern name AFAIK, just mentioning the
technique, for instance, [NSNotificationCenter defaultCenter]).
Tear down, in your case, should be as simple as releasing the MOC. The
other calls (-reset etc) are unnecessary.
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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