[pygtk] destructors not getting called
Wildemar Wildenburger
wildemar at freakmail.de
Sat Aug 5 18:24:35 WST 2006
N. French wrote:
> 1. The App class does not have __del__ called unless I explicitly call
> it in my window destroy callback.
>
> 2. The container classes don't have __del__ called unless I explicitly
> call it (from my App's destructor).
>
> I tested the container classes separately and the destructors get
> called just like you'd expect, which is why I'm thinking this has
> something to do with GTK. Below is my startup code.
I found this in the reference recently, maybe its related:
*quote from the description of gtk.Object*
The "destroy" signal, emitted by the destroy() method asks all code
owning a GTK reference to the object to release its GTK reference. So,
for example, if you call window.destroy() where window is a gtk.Window,
GTK will release the GTK reference count that it owns; if you call
button.destroy() where button is a gtk.Button, button will be removed
from its parent container and the parent container will release its GTK
reference to button. Because these GTK references are released, calling
destroy() should result in freeing all memory associated with an object
(finalizing it) if the GTK reference count reaches zero. However, in
PyGTK the GTK objects are wrapped in a Python object that has its own
reference counting mechanism. The destroy() method does not affect the
Python reference counts. The GTK object associated with a Python object
will not be released until the Python object reference count reaches
zero. Therefore, calling the destroy() method will not result in the
finalization of the GTK object until the Python object is finalized. In
the case mentioned above if a gtk.Button is destroyed using the
destroy() method, it will be removed from its container and unmapped and
unrealized but it will not be finalized because the Python wrapper
object will still exist and hold a reference.
*end quote*
More information about the pygtk
mailing list