GNOME Bugzilla – Bug 662257
GSource reference counting semantics are completely undocumented :(
Last modified: 2018-05-24 13:28:03 UTC
A project I work on uses GLib's main loop at its core. I usually come back to this project after a few (or many) months working on other stuff, so I have a tendency to forget a fair amount of specific knowledge about GLib, and I have to resort to the published APIs at http://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#GSource . One thing I've repeatedly had to fall back to reading sources to figure out are the reference counting semantics for event sources. It would be extremely helpful if the docs noted a returned source's initial reference count (g_source_new: 1 vs. g_timeout_add: 2, since attaching it to a context increments the count?), such that users know when they have to clean things up and how. Thanks!
I agree that we should document this more clearly. However, it is not trivial. The docs need to say that 1. g_timeout_add, g_idle_add, g_source_remove etc are just convenience api to work with the default context. When you are using these, you are never explicitly dealing with GSource structures. 2. GSource structures are ref-counted. g_source_new, g_timeout_source_new, etc return a new reference. Free with g_source_unref(). However, if a source is attached to a main context, you need to use g_source_destroy()
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/467.