does python have useless destructors?

Marcin 'Qrczak' Kowalczyk qrczak at
Mon Jun 14 17:28:18 CEST 2004

On Mon, 14 Jun 2004 08:00:07 -0700, David Turner wrote:

>> > The D programming language somehow contrives to have both garbage
>> > collection and working destructors.  So why can't Python?
>> What happens in D when you make a pointer to a local variable,
>> the variable goes out of scope, and you use the pointer?
>> Undefined behavior? If so, it's unacceptable for Python.
> Are you suggesting that my proposed modification to the destructor
> semantics will result in such misbehaviour?  If so, please tell me why
> you believe that to be the case.

It answers "why can't Python if D can". If D works similarly to C++ here
(I couldn't find the object model details described in D documentation),
it trades safety for speed by embedding objects inside variables. This
makes destructors easy, because you statically know when an object will
be destroyed and you just don't care if someone still refers to it.

But Python doesn't put objects inside variables, so it's impossible to
accurately and quickly find which objects are no longer referred to.
I don't believe D promises to run destructors of heap-allocated objects
automatically in the very moment the last reference to it is dropped.

   __("<         Marcin Kowalczyk
   \__/       qrczak at

More information about the Python-list mailing list