does python have useless destructors?

"Martin v. Löwis" martin at
Tue Jun 15 06:18:33 CEST 2004

Roger Binns wrote:
> Actually I did.

Can you please repeat your proposed solution? I must have
missed it. All I can find is

I would do the same thing that shutdown does.  Run
the destructors, but don't delete the underlying
memory.  Set all the fields to None (just as shutdown
points modules at None).  Finally in a second round
actually free the memory.
(apparently alternative approach of throwing an
exception omitted)

This specifies that you want to do the same thing as
shutdown, but later you say that you don't want to
do the same thing as shutdown does:

I meant that during shutdown the modules are forcibly
garbage collected, and to a certain extent Python
treats their names like weak references

This is not true: In Python, modules are not forcibly
garbage collected at shutdown. Instead, they are
emptied, and explicitly removed from sys.modules.

You also specify "Run the destructors, but don't
delete the underlying memory". This is, unfortunately,
not a complete specification. It does not specify
what to do, and when to do it. While it says
that we should run destructors, it does not say
which objects to run the destructors for.

You clearly don't mean: "After each statement, run
the destructors on all objects". But I cannot guess
what it is that you mean.


More information about the Python-list mailing list