useless destructors

David Turner dkturner at telkomsa.net
Tue Jun 22 12:37:38 EDT 2004


Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote in message news:<pan.2004.06.22.09.56.49.888803 at knm.org.pl>...
> On Tue, 22 Jun 2004 02:36:24 -0700, David Turner wrote:
> 
> > Further to the discussion from earlier titled "does python have
> > useless destructors?", I've posted a brief summary of garbage
> > collection, RAII, and the "using" clause (which is what PEP310's
> > "with" clause amounts to).  The post is here:
> > 
> > http://dkturner.blogspot.com/2004/06/garbage-collection-raii-and-using.html
> 
> You left "for later" a point which makes the last proposition unworkable:
> how to implement selective refcounting in a dynamically typed language?
> Will it still work if the refcounted object is referred to from a plain
> object? The only way I can imagine is to manage refcounts on each object
> passing, returning and rebinding.

To answer your second question first: no, of course it won't -- the
contained object will be destroyed only when the container is garbage
collected.  But of course, that's the behaviour you'd expect.  I don't
see it as a serious concern.

Your first point is well made.  I agree that it would be extremely
difficult to implement deterministic destruction in Python.  As you've
pointed out before, the overhead is considerable on some significant
platforms, and worst of all, it's not limited to cases where
deterministic destruction is used (although I still believe that the
additional overhead for other objects should be pretty minor).

Regards
David Turner



More information about the Python-list mailing list