Re: Crashing resetting or releasing an NSManagedObjectContext
Re: Crashing resetting or releasing an NSManagedObjectContext
- Subject: Re: Crashing resetting or releasing an NSManagedObjectContext
- From: Daniel Kennett <email@hidden>
- Date: Tue, 5 May 2009 09:46:02 +0100
Thank you again for your helpful replies!
On a different note, when you comment out the "for (VetVisit" code,
does it still crash on a VetVisit, or does it crash on a
"Medication" object?
It still crashes on a VetVisit object.
I don't think I've solved the problem, but I have stopped it crashing.
Putting a breakpoint on [VetVisit -release] showed me that
NSFastEnumeration was releasing the object:
for (VetVisit *visit in [self vetVisits]) { // <-- Stack trace for
[VetVisit -release] comes from here
[visit className];
}
I solved the crash by doing this:
NSArray *visits = [[self vetVisits] allObjects];
for (VetVisit *visit in visits) {
[visit className];
}
... and now it works fine! The accessors for the vetVisits set are
just the ones made by the Core Data wizard thing - they're declared
like this:
@property (nonatomic, retain) NSSet* vetVisits;
... and implemented with this:
@dynamic vetVisits;
So, I've stopped the crash, but I'm thoroughly confused about what's
going on and think I'm just papering over the problem.
Thanks,
-- Daniel
_______________________
email@hidden
http://www.kennettnet.co.uk
Please include previous messages in any reply you send.
On 4 May 2009, at 23:44, Keary Suska wrote:
On May 1, 2009, at 2:24 AM, Daniel Kennett wrote:
Thanks for your reply. Yes, I have code that triggers relationship
faults, and removing that code solves the problem. However, I need
that code to work! :-)
When fetching the data from the object tree, I call a method on the
pet instance called -pertinentActions. This method loops through
various relationships, calling -pertinentAction on each child
object. I've ruled out the -pertinentAction method, since calling -
className on the child objects also causes the crash to happen.
I've also double and triple checked my retains and (auto)releases
and they're all balanced.
My recommendation is don't check them *prove* them. If you release
or autorelease any vetvisit object, comment it out and see if the
problem goes away. I say this because I have had, and just about any
programmer probably has, stared at the exact glaring error over and
over again and not seen it.
In any case, there is an overrelease happening, which means
somewhere retains are *not* balanced, and 99.9999% of the time, it's
the programmer's code. But you have to find out how it is happening,
so it's time to bring out Instruments--it can tell you who is the
culprit and where it is.
On a different note, when you comment out the "for (VetVisit" code,
does it still crash on a VetVisit, or does it crash on a
"Medication" object?
_______________________________________________
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