Can you use g_mem_profile with GTK+ apps?



Hey,

I was wondering how one would use the GLib memory profiling tools withing a GTK+ application. My understanding is that GTK+ will leave cached stuff in memory "unfreed" as far as profilers are concerned. For example, take the following application:

#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
    GtkWidget *window;
 
    g_mem_set_vtable (glib_mem_profiler_table);
    g_atexit (g_mem_profile);
 
    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

    gtk_widget_show_all (window);

    gtk_main ();
 
    return 0;
}


When this runs, the g_mem_profile function will report memory leaks. It was ran as follows:

export G_SLICE=always-malloc
export G_DEBUG=gc-friendly
./a.out
...
GLib Memory statistics (failing operations):
 --- none ---
Total bytes: allocated=664682, zero-initialized=47892 (7.21%), freed=508372 (76.48%), remaining=156310
-- 
- Micah Carrick
  Freelance Developer
  http://www.micahcarrick.com | http://www.gtkforums.com


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