[C++-sig] Re: Pyste feature: class member deletion o
RaoulGough at yahoo.co.uk
Tue Nov 11 18:05:02 CET 2003
"Niall Douglas" <s_sourceforge at nedprod.com> writes:
> On 9 Nov 2003 at 14:52, David Abrahams wrote:
>> > I can't see how that would happen. The bottom-most children (who
>> > don't have any extra things holding a reference to them) when
>> > deleted decrement the reference count of their parents. If a
>> > parent has no other thing using it, it too gets deleted.
>> The children won't get deleted, because they are part of a reference
>> cycle. Please think a bit more before arguing with me.
> You're right - I was forgetting that the parent object's __del__ only
> gets called when its reference count goes to zero, which never could
> happen if its children all were holding a reference to it.
Generally, if A owns B and B owns A, you can solve the reference
counting problems by treating the combined A-B cycle as a single
object. You introduce a third object C that owns the combined A-B
cycle, and nobody else is allowed to store any references to A or B as
individual objects. When C gets destroyed, it breaks one of the links
in the cycle before disappearing. Since nobody else had a reference to
A or B, they both get destroyed at the same time.
(setq dabbrev-case-fold-search nil)
More information about the Cplusplus-sig