Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
pygobject
pygobject
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 239
    • Issues 239
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 10
    • Merge Requests 10
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • GNOME
  • pygobjectpygobject
  • Issues
  • #136

Closed
Open
Opened Jul 09, 2017 by bugzilla-migration@bugzilla-migrationReporter

Problematic use of Gtk.Builder in examples and demos

Submitted by lovetox

Link to original bug (#784728)

Description

The Gtk.Builder demo/example in the repo

https://gitlab.gnome.org/GNOME/pygobject/blob/master/examples/demo/demos/builder.py

in this example a reference is set to the Gtk.Builder object on self, then with connect_signals(self), Gtk.Builder gets a reference of BuilderApp. I dont know what Gtk.Builder exactly does with that reference but from my tests it creates a ref cylce that it seems python can not detect.

Hence neither Gtk.Builder nor BuilderApp is garbage collected ever.

Just dont quit Gtk on destroy, and create a list with some million entrys on the class.

if you run this and close the window, the class is never garbage collected because Gtk.Builder holds somewhere a reference to it. The memory is not released.

If you run the same example but comment out "self.builder.connect_signals(self)" the class is garbage collected.

Im aware that this could be considered not a bug. But then we should at least hint somewhere in the documentation or in the examples that this ref cycle has to be broken somehow.

Im curious how other devs handle this, or if they are aware of it.

Here my test:

import os

from gi.repository import Gtk


class BuilderApp:
    def __init__(self, demoapp):
        self.demoapp = demoapp

        self.builder = Gtk.Builder()
        if demoapp is None:
            filename = os.path.join('data', 'demo.ui')
        else:
            filename = demoapp.find_file('demo.ui')

        self.builder.add_from_file(filename)
        self.builder.connect_signals(self)

        window = self.builder.get_object('window1')
        window.connect('destroy', self.quit_activate)
        window.show_all()
        self.list_ = []
        for x in range(10000000):
            self.list_.append('test')


    def about_activate(self, action):
        about_dlg = self.builder.get_object('aboutdialog1')
        about_dlg.run()
        about_dlg.hide()

    def quit_activate(self, action):
        return


def main(demoapp=None):
    BuilderApp(demoapp)
    Gtk.main()

if __name__ == '__main__':
    main()
Edited Jan 12, 2018 by Christoph Reiter
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: GNOME/pygobject#136