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 688064 - Object.connect_object holds strong reference to object argument
Object.connect_object holds strong reference to object argument
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 692918
Blocks:
 
 
Reported: 2012-11-10 23:26 UTC by Simon Feltman
Modified: 2018-01-10 20:20 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon Feltman 2012-11-10 23:26:43 UTC
One of the main purposes of connect_object is the signal should disconnect automatically based on the lifetime of the object argument. This is not working correctly in python likely due to the method holding a strong reference to the object argument. This is observed as follows:

import weakref, gc
from gi.repository.GObject import Object, Property

class O(Object):
    foo = Property(type=int)
    def callback(self, *args):
        print(args)

o1 = O()
o2 = O()
w1 = weakref.ref(o1)
w2 = weakref.ref(o2)

o1.connect_object('notify', O.callback, o2)
o1.notify('foo')  # callback prints
del o2
gc.collect()

o1.notify('foo')  # callback still prints
w2()  # <O object...>  (should be None)

del o1
gc.collect()
w1()  # None
w2()  # None (after the reference held by the w1 connection is released).



The fix should probably be to use a weak reference to the python object (o2) passed in if possible.
Comment 1 Simon Feltman 2014-08-12 05:54:56 UTC
Added a deprecation warning when using connect_object() with non-GObject arguments: https://git.gnome.org/browse/pygobject/commit/?id=86fb12b
Comment 2 GNOME Infrastructure Team 2018-01-10 20:20:05 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/36.