GNOME Bugzilla – Bug 686140
Objects returned from vfuncs are leaked
Last modified: 2012-10-15 12:12:31 UTC
This is easily shown by implementing a TreeModel get_iter vfunc and tracking its return with a weak reference: import weakref import gc from gi.repository import GObject, Gtk refs = weakref.WeakSet() class Model(GObject.GObject, Gtk.TreeModel): def do_get_iter(self, path): it = Gtk.TreeIter() it.user_data = 123 refs.add(it) return (True, it) model = Model() # This returns a new wrapper and copy of the held struct. it = model.get_iter(0) gc.collect() assert len(refs) == 0, 'a reference should not be held: %s' % refs.pop()
Created attachment 226454 [details] [review] Trivial fix and added unittest
Review of attachment 226454 [details] [review]: Thanks! Please commit, and also cherry-pick onto 3.4 branch.
Comment on attachment 226454 [details] [review] Trivial fix and added unittest Pushed to both master and pygobject-3-4