[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: memory leak in gtk
- From: "c f" <cfekete1 gmail com>
- To: "Michael Lamothe" <michael lamothe gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: memory leak in gtk
- Date: Thu, 22 Nov 2007 04:56:17 +0100
Hi Michael,
Thanks for your suggestion.
Actually I have not mentioned but I also tried to decrease the ref
count of the mainWindow (just to be sure). In theory it is already
destroyed at this point as the main quit is called in the destoyed
handler of the main window. In that case (unref), GTK showed the
assertion: object is not a valid g object so the mainWindow was
destroyed correctly.
Anyhow I have tried to apply your suggestion but mainWindow does not
exists at this point.
> You really
> don't need to do this because it will be destroyed when the
> application terminates 0.01 seconds after that line.
I do not know if this (thousands of memory leaks) is normal in a GTK
application, but it is quite hard to find your own memory leaks if
there are a lot from other components.
Thanks,
Csaba
On Nov 22, 2007 12:10 AM, Michael Lamothe <michael lamothe gmail com> wrote:
> 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]