Memory leaks?



I've got a GTK+ based program and I'm trying to clean up the memory leaks. I'm running it through valgrind using the instructions here:
http://live.gnome.org/Valgrind

I'm building against GTK 2.10.4.

Even with the suppressions, I'm getting lots of memory leaks reported.

First question: If I call gtk_main_quit() in my toplevel window's "destroy" handler, will that also destroy the window, or do I need to explicitly call gtk_widget_destroy?

Note, however, that for the purposes of this output, I'm not even calling gtk_main(), I'm just creating the widgets and then gtk_widget_destroy()ing the toplevel window. So far as I can tell, every other widget that gets created is either explicitly destroyed, or inserted into another widget with the root being the toplevel GtkWindow.

I have to say that I'm not a big fan of glib's reference-counting approach. Reference counting is great so long as it's done automatically, such as with boost::shared_ptr, but in a C-based environment it's too easy to get confused about what needs to be explicitly cleaned up and what doesn't.

Here's a sample of my Valgrind output:
==5968== 17 bytes in 1 blocks are definitely lost in loss record 57 of 12,045
==5968==    at 0x4A05D4B: malloc (vg_replace_malloc.c:207)
==5968==    by 0x3782033819: (within /lib64/libglib-2.0.so.0.1200.3)
==5968==    by 0x37820341A5: (within /lib64/libglib-2.0.so.0.1200.3)
==5968==    by 0x3782033BFA: g_malloc (in /lib64/libglib-2.0.so.0.1200.3)
==5968==    by 0x3782045A7E: g_strdup (in /lib64/libglib-2.0.so.0.1200.3)
==5968==    by 0x3ADAF1A72F: gtk_label_set_text (in /usr/lib64/libgtk-x11-2.0.so.0.1000.4)
==5968==    by 0x3782429C8F: g_type_create_instance (in /lib64/libgobject-2.0.so.0.1200.3)
==5968==    by 0x37824118BC: (within /lib64/libgobject-2.0.so.0.1200.3)
==5968==    by 0x378240F723: g_object_newv (in /lib64/libgobject-2.0.so.0.1200.3)
==5968==    by 0x378241014B: g_object_new_valist (in /lib64/libgobject-2.0.so.0.1200.3)
==5968==    by 0x3782410380: g_object_new (in /lib64/libgobject-2.0.so.0.1200.3)
==5968==    by 0x3ADAF1A9E1: gtk_label_new (in /usr/lib64/libgtk-x11-2.0.so.0.1000.4)
==5968==    by 0x41AE28: create_slider_refinement (ui.c:988)
==5968==    by 0x41B82E: create_image_processing_box (ui.c:1172)
==5968==    by 0x41BEC1: createMainWindow (ui.c:1244)
==5968==    by 0x40DF36: main (main.c:129)

Lots of similar stuff like that. The label is *definitely* being inserted into the toplevel window, since I can see it when I let the main loop come up. In fact, judging by the number of leak messages, I'm guessing that none of my widgets are being entirely released, despite the top-level call to gtk_widget_destroy().

Any ideas?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]