Python equivalent of C++'s virtual destructors?

David C. Ullrich david_ullrich at my-deja.com
Wed Aug 2 12:59:10 EDT 2000


In article <8F838F369gmcmhypernetcom at 199.171.54.194>,
  gmcm at hypernet.com (Gordon McMillan) wrote:
> 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.

    I didn't mean to imply this had been keeping me up at night,
I'd just sorta assumed that Python called everything.__dell__
on exit. Win32 cleans up any memory and resources on exit, so
that's no problem - the possible problem would be things you
want to clean up that are not memory or resources. (No, no
example springs to mind, which is why I was able to sleep
last night even after noticing that bit in the docs.)

> - Gordon
>

--
Oh, dejanews lets you add a sig - that's useful...


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list