[9644] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] Re: style usage + memory leak

daemon@ATHENA.MIT.EDU (Owen Taylor)
Thu Oct 29 14:53:37 1998

To: gtk-list@redhat.com
From: Owen Taylor <otaylor@redhat.com>
Date: 29 Oct 1998 14:45:26 -0500
In-Reply-To: smolitor@insight-tech.com's message of "Thu, 29 Oct 1998 10:00:36 -0600"
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com


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

-- 
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post