does python have useless destructors?

Carl Banks imbosol at aerojockey.invalid
Sun Jun 13 20:05:19 CEST 2004

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.

Are you aware that CPython already does this?

I assumed that you knew this, and I assumed that you were aware of the
limitations of reference counting (in particular, that you cannot rely
on a reference count ever going to zero).  That is why I took your
statement to mean something else.

But if I assumed incorrectly, then you should know this: reference
counting simply doesn't take away the need to explicitly release
resources, unless you don't care about robustness (that thing you
claimed RAII is).  It works for the common case most of the time, but
the danger always lurks that a reference could get trapped somewhere,
or a cycle could arise.

If you don't want that stuff happening, then you better use the
explicit finally block, reference counted finalization or not.

CARL BANKS            
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon

More information about the Python-list mailing list