Re: style usage + memory leak




smolitor@insight-tech.com (Stephen Molitor) writes:

> Robert Roebling wrote:
> 
> > No. When I create the style, its ref count is 1. When I then
> > assign it to a widget, I assume the widgets will raise the
> > ref count to 2. Without unref after assigning it the widget
> > would unref the style upon its own destruction leaving
> > the ref count at 1 -> memory leak.
> 
> I thought that when you created something in Gtk+, it was "floating," with
> no reference count, until you assigned it to something.  So when you create
> the style, it is "floating" (ref count 0), until you assign it to a widget,
> raising the ref count to 1.  The danger zone is when
> an object is "floating," the interval between when it is created and when it
> is assigned to something.  If you create the style and don't assign it to
> any widget, then you would have a memory leak.

That system only applies to GtkObject and its descendents
(GtkWidget, GtkAdjustment, ...)

All other things in GTK+ and GDK - GdkWindows, GtkStyle, etc,
reference count "normally" - the reference count is 1 upon
creation, and you are responsible for dereferencing them.

Often, this means creating an object, passing it to GTK+, then
unreferencing it immediately - 

 pixmap = gdk_pixmap_create_from_xpm_d (...);
 widget = gtk_pixmap_new (pixmap, NULL);
 gdk_pixmap_unref (pixmap);
 
Regards,
                                        Owen



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