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 686140 - Objects returned from vfuncs are leaked
Objects returned from vfuncs are leaked
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Simon Feltman
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-10-15 11:00 UTC by Simon Feltman
Modified: 2012-10-15 12:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Trivial fix and added unittest (3.23 KB, patch)
2012-10-15 11:43 UTC, Simon Feltman
committed Details | Review

Description Simon Feltman 2012-10-15 11:00:40 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()
Comment 1 Simon Feltman 2012-10-15 11:43:38 UTC
Created attachment 226454 [details] [review]
Trivial fix and added unittest
Comment 2 Martin Pitt 2012-10-15 11:58:40 UTC
Review of attachment 226454 [details] [review]:

Thanks! Please commit, and also cherry-pick onto 3.4 branch.
Comment 3 Simon Feltman 2012-10-15 12:12:18 UTC
Comment on attachment 226454 [details] [review]
Trivial fix and added unittest

Pushed to both master and pygobject-3-4