Re: memory leak in gtk



I'm no master profiler but I think that you'll want to put a
gtk_widget_destroy(mainWindow); after the gtk_main();.  You really
don't need to do this because it will be destroyed when the
application terminates 0.01 seconds after that line.  But if you feel
you must then go for it.  I also like to tie-off loose ends.

Thanks,

Michael

On 22/11/2007, c f <cfekete1 gmail com> wrote:
Hi,

I have made a simple application with a top level window:

"
#include <gtk/gtk.h>
#include <mcheck.h>

gboolean OnDeleteHandler(GtkWidget *sender,
                         GdkEvent  *event,
                         gpointer   data)
{
        return FALSE;
}

void OnDestroyHandler(GtkWidget *sender, gpointer data)
{
        gtk_main_quit();
}


int main(int argc, char *argv[])
{
mtrace();

        gtk_init(&argc, &argv);

        GtkWidget *mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

        g_signal_connect(G_OBJECT(mainWindow), "delete_event",
                G_CALLBACK(OnDeleteHandler), NULL);
        g_signal_connect(G_OBJECT(mainWindow), "destroy",
                G_CALLBACK(OnDestroyHandler), NULL);

        gtk_widget_show_all(mainWindow);

        gtk_main();

//      gtk_exit(0);
//      exit(0);

  return EXIT_SUCCESS;
}
"
I have used mtrace to check for memory leaks. In this simple
application there are more than 5000 memory allocation which is not
freed.

I have checked the GTK documentation and it states that gtk_exit free
all resources allocated for GTK+. gtk_exit is depricated and using
exit is recommended. I have tested both but non of them improved the
situation (still more than 5000 leaks).

Please could you help if I missed some cleanup in my application or
what is happening?

Thanks,
Csaba
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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