RE: gtkevent memory leak



Ok, I read the article and it was helpful.  I don't have a full grasp of how
glib manages memory yet.

Looking into the code more, I see that a GObject should have it's signal
handlers destroyed when it's no longer floating and gets unreferenced for
that last time.

A note about glib_set_memtrace(): it is my own function that merely turns on
some fprintf's  out of g_*alloc* and g_free.  Which I run the output through
a script which tells me what happened.

I changed my code to add the widget to a container and that did free up the
memory that I was concerned about.  But I still have 347 bytes unaccounted
for.  I'll keep looking.  Thanks for the info.

Brandon M. Reynolds                    Ph: (330) 644-3059
Systems Engineer                       Fax: (330) 644-8110
Commercial Timesharing Inc.            Email: bmr comtime com


> -----Original Message-----
> From: Owen Taylor [mailto:otaylor redhat com]
> Sent: Thursday, December 11, 2003 5:51 PM
> To: Brandon M. Reynolds
> Cc: 'gtk-devel-list gnome org'
> Subject: Re: gtkevent memory leak
> 
> 
> On Thu, 2003-12-11 at 17:15, Brandon M. Reynolds wrote:
> > It seems that gtkentry has some memory leaks.  Ignore the
> > glib_set_memtrace() calls.  I seem to have to call
> > g_signal_handlers_destroy() because there are several 
> signal handlers
> > assigned to im_context in gtk_entry_init().  I guess these 
> should be dealt
> > with in gtk_entry_finalize().
> 
> A) glib_set_memtrace() is very much not useful, and may *cause*
>    memory leaks, if I remember correctly.
> 
> B) Calling gtk_widget_destroy() on a newly created child 
>    widget will leak the widget. Understanding why this is 
>    so requires understanding the concept of  floating
>    reference counts:
> 
>    http://developer.gnome.org/doc/GGAD/z57.html
> 
>    has an explanation. (it's out of date in other way,s
>    but this hasn't changed.)
> 
> D) You cannot call g_signal_handlers_destroy() on any 
>    GObject
> 
> E) You cannot call g_free() on any GObject.
> 
> Regards,
> 					Owen
> 
> 
> > #include <gtk/gtk.h>
> > int main(int argc, char *argv[])
> > {
> >   GtkWidget *widget;
> >   extern void glib_set_memtrace(int);
> > 
> >   gtk_init (&argc, &argv);
> > 
> >   widget = gtk_entry_new();
> >   gtk_widget_destroy(widget);
> >   g_free(widget);
> > 
> >   glib_set_memtrace(1);
> > 
> >   widget = gtk_entry_new();
> > 
> >   g_signal_handlers_destroy(GTK_ENTRY(widget)->im_context);
> >   gtk_widget_destroy(widget);
> > 
> >   g_free(widget);
> > 
> >   glib_set_memtrace(0);
> > 
> >   return 0;
> > }
> 
> 



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