Hi, I'm trying to find a way to test for memory leaks in GTK+ apps. I've created a very simple HelloWorld app and profiled it with valgrind. The source code and the valgrind output are attached. I have run valgrind as: G_SLICE=always-malloc G_DEBUG=gc-friendly \ valgrind --tool=memcheck --leak-check=full --leak-resolution=high \ -num-callers=20 ./helloworld &> helloworld.out The result was: ==15450== LEAK SUMMARY: ==15450== definitely lost: 429 bytes in 5 blocks. ==15450== indirectly lost: 180 bytes in 13 blocks. ==15450== possibly lost: 800 bytes in 20 blocks. ==15450== still reachable: 362,035 bytes in 9,875 blocks. ==15450== suppressed: 0 bytes in 0 blocks. I'm surprised that even for such a simple program I still get memory leaks. So I'm probably doing something wrong. Here are the gtk/glib versions I used: $ pkg-config gtk+-2.0 --modversion 2.12.9 $ pkg-config glib-2.0 --modversion 2.16.3 I am using Debian unstable. The exact packages I'm using are: libglib2.0-dev 2.16.3-2 libgtk2.0-dev 2.12.9-3 valgrind 1:3.3.0-1 Please help me check for memory leaks in GTK. Is valgrind the tool of choice for testing memory leaks with gtk? Is there other free better tool? Thanx. Johnny
#include <gtk/gtk.h> static void destroy(GtkWidget*, gpointer); int main(int argc, char* argv[]) { gtk_init(&argc, &argv); GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Hellow World"); gtk_widget_show(window); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); gtk_main(); return 0; } void destroy(GtkWidget* window, gpointer data) { gtk_main_quit(); }
Attachment:
helloworld.out.zip
Description: Zip archive