Re: style usage + memory leak
- From: Owen Taylor <otaylor redhat com>
- To: gtk-list redhat com
- Subject: Re: style usage + memory leak
- Date: 29 Oct 1998 14:45:26 -0500
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]