GNOME Bugzilla – Bug 774066
GtkHeaderBar does not unref all GtkBox and GtkSeparator it creates
Last modified: 2016-11-10 20:04:18 UTC
After setting GOBJECT_DEBUG=objects comparing the outputs of the following program run with ITERATIONS set to 2 and 1: #include <gtk/gtk.h> #ifndef ITERATIONS #define ITERATIONS 2 #endif int main (int argc, char *argv[]) { if (gtk_init_check (&argc, &argv)) for (gint i = 0; i < ITERATIONS; ++i) { GtkWidget *dialog = gtk_color_chooser_dialog_new ("Open File", NULL); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } return 0; } the number of objects alive at exit increases for the presence of few GtkBox and GtkSeparator created by GtkHeaderBar. in https://git.gnome.org/browse/gtk+/tree/gtk/gtkheaderbar.c?h=gtk-3-22#n340 a GtkBox and a GtkSeparator are created and when they're not necessary they're destroyed: https://git.gnome.org/browse/gtk+/tree/gtk/gtkheaderbar.c?h=gtk-3-22#n458 but that's not enough, apparently to remove the last reference from a widget not inserted in a parent widget it is necessary to g_object_unref (g_object_ref_sink (box/separator)); In this case it is probably simpler to initialize 'box' = NULL and get rid of the variable 'n_children'. When that var would be incremented to 1 create 'box' and 'separator' and after the loop continue if 'box' is still NULL.