Python equivalent of C++'s virtual destructors?

Gordon McMillan gmcm at hypernet.com
Tue Aug 1 13:37:03 EDT 2000


david_ullrich at my-deja.com wrote:

>In the docs (under "Basic Customization") it says

[snip]

> "Note that it is possible (though not recommended!) for the
>__del__ method to postpone destruction of the instance by
>creating a new reference to it. It may then be called at a
>later time when this new reference is deleted. It is not
>guaranteed that __del__ methods are called for objects
>that still exist when the interpreter exits."
>
>The last sentence is news to me - it's not clear to me
>what a person _is_ supposed to do to guarantee things
>get cleaned up when the interpreter exits.

Finalization at end-of-process is a messy job (it's probably impossible to 
find a path through the graph of object references that destroys things in 
an order that would give "correct" behavior in all circumstances). Barring 
circular references, you're probably OK.

OTOH, on any OS worthy of the name (ie, anything better than Win3.1 
<wink>), the OS guarantees that it all gets cleaned up.

- Gordon



More information about the Python-list mailing list