[grisbi-devel] [PATCH 04/15] Fix huge memory leak in gtk_combofix.c

RĂ©mi Cardona remi at gentoo.org
Sat Mar 9 16:53:56 CET 2013


GtkWindows are referenced by Gtk's top-level widget list.

GtkTreeStore, GtkTreeModelFilter and GtkTreeModelSort are all derived
from GObject (and not GInitiallyUnowned like all widgets) so they are
created with a reference of one. We need to explicitly unref them.

The store and model filters hold large amounts of memory: proportional to
the number of categories and payees. In my case, this represents around
300 KB.
---
 src/gtk_combofix.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/gtk_combofix.c b/src/gtk_combofix.c
index 6bd2969..e3cb602 100644
--- a/src/gtk_combofix.c
+++ b/src/gtk_combofix.c
@@ -675,6 +675,7 @@ static void gtk_combofix_init ( GtkComboFix *combofix )
 
     /* set the popup but don't show it */
     priv -> popup = gtk_window_new ( GTK_WINDOW_POPUP );
+    g_object_ref ( G_OBJECT ( priv -> popup ) );
     g_signal_connect ( G_OBJECT ( priv -> popup ),
                         "key-press-event",
                         G_CALLBACK (gtk_combofix_popup_key_press_event),
@@ -786,6 +787,15 @@ static void gtk_combofix_finalize ( GObject *combofix )
     if ( priv -> old_entry && strlen ( priv -> old_entry ) )
         g_free ( priv -> old_entry );
 
+    /* Unref/free the model first, to workaround gtk/gail bug #694711 */
+    gtk_tree_view_set_model ( GTK_TREE_VIEW ( priv -> tree_view ), NULL );
+    g_object_unref ( priv -> model_sort );
+    g_object_unref ( priv -> model_filter );
+    g_object_unref ( priv -> store );
+
+    gtk_widget_destroy ( priv -> popup );
+    g_object_unref ( priv -> popup );
+
     G_OBJECT_CLASS ( gtk_combofix_parent_class ) -> finalize ( combofix );
 }
 
-- 
1.8.1.4



More information about the devel mailing list