Python equivalent of C++'s virtual destructors?

David C. Ullrich david_ullrich at my-deja.com
Wed Aug 2 13:04:33 EDT 2000


In article <8m7gui1q0f at news1.newsguy.com>,
  "Alex Martelli" <alex at magenta.com> wrote:
> <david_ullrich at my-deja.com> wrote in message
> news:8m6v04$2q1$1 at nnrp1.deja.com...
>     [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.
>
> Calling delete on all global variables should do it, if
> it's so crucial, unless of course there are cycles...
>
> Personally, I rely on the operating system cleaning up
> after me as soon as my process is over.  Lazy, but...

    That's what I do too, and it works just fine. Wouldn't
work for something that needs to be cleaned up other than
memory or resources handled by the OS, though.

    Not important, but when you say "Calling delete on
all global variables should do it" it raises the question
"Well of course. But the question is _where_ do you call
delete on those global variables? In the body of the
the_interpreter.__on_exit__ method???"

DU

> Alex
>
>

--
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