After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 107697 - gtk.Widget subclass object destroyed prematurely
gtk.Widget subclass object destroyed prematurely
Status: RESOLVED DUPLICATE of bug 92955
Product: pygtk
Classification: Bindings
Component: general
1.99.x/2.0.x
Other All
: Normal normal
: ---
Assigned To: Python bindings maintainers
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2003-03-06 05:31 UTC by Tim Evans
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Simplified example of the described problem (679 bytes, text/plain)
2003-03-06 05:34 UTC, Tim Evans
Details

Description Tim Evans 2003-03-06 05:31:54 UTC
This bug is present in pygtk-1.99.14, but does not appear to be present in
pygtk-1.99.10, and I'm not sure about anything in between.

In certain conditions, an instance of a class that inherits from a gtk
widget can be garbage collected (in python, not gtk) while the object is
still active and still required.  The following conditions must exist (I
think) for this to occur:
 1. The class inherits from a gtk.Widget subclass.
 2. There are references, in python, to the instance of the class, but it
is displayed on the screen.
 3. The instance has connected one of its signals to a method of itself
(e.g. self.connect('clicked', self._on_clicked)).
 4. A cyclic garbage collection run has occurred.

I will attach a simplified example that demonstrates the error.

Workaround:

If the current code looks like this:

    class MyButton(gtk.Button):
        def __init__(self, *args):
            gtk.Button.__init__(self, *args)
            self.connect('clicked', self.on_clicked)

        def on_clicked(self, widget):
            ...

Replace with this:

    class MyButton(gtk.Button):
        def __init__(self, *args):
            gtk.Button.__init__(self, *args)
            self.connect('clicked', self.__class__.on_clicked)

        def on_clicked(self):
            ...

Relying on the fact the the first argument to a handler is the widget,
which in this case is the same as 'self'.
Comment 1 Tim Evans 2003-03-06 05:34:11 UTC
Created attachment 14808 [details]
Simplified example of the described problem
Comment 2 James Henstridge 2003-03-06 05:55:30 UTC
This is a duplicate (hopefully I can get the bug fixed for 1.99.16)

*** This bug has been marked as a duplicate of 92955 ***