Objects are leaked when using Template Callbacks or connecting signals
If an object is created and a callback defined with the decorator @Gtk.Template.Callback()
is setup within that object, or even when the callback is connected programatically to a signal, the object won't be disposed until the application closes.
For example (the full reproducer can be found at https://gitlab.gnome.org/somas/leaks_reproducer/):
We spawn window 1. Window 1 has a callback, the handler set up in the UI file and defined using the decorator. We spawn window 2. We close window 1. At this point window 1 has not been freed.
We can see that in the reproducer because window 2 holds a weak reference to window 1, and the callback set up for when the weak reference is dropped is never called. I also added a periodic print for all the referrers of window 1, and the callback function is shown there.