Re: Possible memory leak in simple code



Hi,
I have the same problem. The memory leak appears during gtk_widget_destroy
also, why can this happen and how could I solve it?


Ian King [ES] wrote:
> 
> Hi,
> 
> Below is some simple code that creates a window and an event box, sinks 
> both to retain the reference, shows the window, and then constantly add 
> and remove the event box to and from the window.  However when the code 
> is running the heap keeps growing, the code is compiled on the latest 
> OpenSolaris version and pmap shows the heap is at a very large size, 
> running the binary under dbx using 'check -memuse' shows that a large 
> number of allocations are being made by _XEnq
> 
>   Total    % of Num of  Avg    Allocation call stack
>   Size      All Blocks  Size
> ========== ==== ====== ======  =======================================
>   10222888  69%  98297    104  _XEnq < _XReply
> 
> It looks like gtk is performing asynchronous calls to X to retrieve some 
> meta information but I haven't looked in to this too deeply, is this a 
> known leak or will this memory eventually get reclaimed?
> 
> Thanks for your time
> 
> Ian King
> 
> 
> #include <gtk/gtk.h>
> 
> int main( int   argc,
>           char *argv[] )
> {
> 
>     GtkWidget *window;
>     GtkWidget *event_box;
> 
>     gtk_init (&argc, &argv);
> 
>     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>     g_object_ref ((GObject*)window);
>     gtk_object_sink ((GtkObject*)window);
> 
>     event_box = gtk_event_box_new();
>     g_object_ref((GObject*)event_box);
>     gtk_object_sink((GtkObject*)event_box);
> 
>     gtk_widget_show(window);
> 
> 
>     for (int i = 0; i < 100000; i++)
>     {
>         gtk_container_add((GtkContainer*) window, event_box);
>         gtk_container_remove((GtkContainer*) window, event_box);
>     }
>     return 0;
> }
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 
> 

-- 
View this message in context: http://www.nabble.com/Possible-memory-leak-in-simple-code-tp18877739p19426241.html
Sent from the Gtk+ - General mailing list archive at Nabble.com.



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