Object.connect_object holds strong reference to object argument
Submitted by Simon Feltman
Link to original bug (#688064)
Description
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.
Depends on
Edited by Christoph Reiter