__del__ in classes derived from Tkinter classes

Fredrik Lundh fredrik at pythonware.com
Sun Jul 21 08:00:12 EDT 2002


Petr Klyushkin wrote:

> So, when will Python object be destroyed?  Suppose, I have
> following code:
>
> def f():
>   test2 = Test()
> f()
>
> When will test2 (Python object! not a Tk widget it represents)
> be destroyed?

maybe when the function returns.  maybe somewhat later.
maybe when the interpreter exits.  possibly never at all.

>  Fredrik> (and using __del__ is usually bad style even outside
>  Fredrik> Tkinter, but that's another story).
>
> Why?

you don't know when they're called, you don't know if they're
called, and you don't know in what state the system is when
they are called.

for more info, search google for "finalizers are bad", or variations
thereof.

</F>





More information about the Python-list mailing list