[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFA: NSAutoreleasePool ivar cleanup
From: |
David Ayers |
Subject: |
Re: RFA: NSAutoreleasePool ivar cleanup |
Date: |
Thu, 24 Mar 2011 10:50:03 +0100 |
Am Donnerstag, den 24.03.2011, 09:45 +0000 schrieb Richard
Frith-Macdonald:
> >> If you look at the implementation of -dealloc, you will see that in it
> >> the child removes itsself from its parent (by clearing
> >> parent->_child).
> >> You can be sure that _child is set to nil ... if it didn't, the while
> >> loop would never terminate.
BTW: This was the symptom. A stack overflow due to two
NSAutoreleasePools bouncing dealloc's to each other... so the chain got
corrupted somehow.
> >> Your patch, setting _child to nil after deallocating it, ought to have
> >> no effect (other than wasting a tiny amount of cpu time) unless you
> >> have some problem elsewhere which is corrupting the _child ivar during
> >> the call to dealloc (after the point where it is set to nil). As far
> >> as I can see the only thing going on there is pushing the deallocated
> >> pool to the cache ... perhaps a problem in the cache? More likely I
> >> would have thought, would be memory corruption caused by another
> >> thread.
> >
> > The patch set's the _child ivar of the receiver of emptyPool to nil.
> > The dealloc implementation set's the _child ivar of the _child to nil.
>
> The -dealloc implementation also sets the _child ivar of the receiver of
> -emptyPool to nil.
>
> > I think the _child ivar of the receiver of emtpyPool will retain the
> > reference to the cached but invalidated pool.
>
> No, because [_child dealloc] will have set _child to nil.
>
> Consider two pools, R and C where C is the child of R.
>
> R->_child == C
> C->_parent = R
>
> If you call [R emptyPool]
> that calls [_child dealloc] (ie [C dealloc])
> and [C dealloc] sets C->_parent->_child to nil and then sets C->_parent t nil
> as well
> so when you get back into [R emptyPool], R->_child (which was
> C->_parent->_child) has been set to nil and the while loop terminates.
OK, I got you.. I'll have investigate further. I think I found the
culprit but I don't yet understand why how the chain got corrupted yet.
Cheers,
David
--
David Ayers - Team Austria
Free Software Foundation Europe (FSFE) [] (http://www.fsfe.org)
Join the Fellowship of FSFE! [][][] (https://fsfe.org/join)
Your donation powers our work! || (http://fsfe.org/donate)