GNOME Bugzilla – Bug 688064
Object.connect_object holds strong reference to object argument
Last modified: 2018-01-10 20:20:05 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.
Added a deprecation warning when using connect_object() with non-GObject arguments: https://git.gnome.org/browse/pygobject/commit/?id=86fb12b
-- 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.