does python have useless destructors?
dkturner at telkomsa.net
Mon Jun 14 09:05:45 CEST 2004
Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote in message news:<pan.2004.06.13.17.40.22.653064 at knm.org.pl>...
> On Sun, 13 Jun 2004 10:24:14 -0700, David Turner wrote:
> > Objects that define __del__ shall have a reference count, which is
> > incremented when names are bound to the object and decremented when
> > those names go out of scope. The __del__ method is called when the
> > reference count reaches zero. This mechanism is orthogonal to garbage
> > collection.
> It's not statically known which variables hold objects which define __del__.
> This implies that you must walk over all local variables of all function
> activations, in addition to GC overhead, and you must manage reference
> counts in all assignments. I'm afraid it's unacceptable.
You don't need static knowledge of which names refer to deterministic
objects. You only need to know at three points: when binding a name,
when exiting a function scope, and when calling __del__ on an object.
In all three cases, you have immediate access to a list of objects
that are to be unreferenced.
So what's the problem? The vast majority of objects I suspect will
not have __del__ methods, so the reference counting that has to be
performed is minimal.
More information about the Python-list