Re: [gtk-list] Styles, unref'ing, and free'ing.
- From: Havoc Pennington <hp redhat com>
- To: David Allen <s2mdalle titan vcu edu>
- Cc: gtk-list redhat com
- Subject: Re: [gtk-list] Styles, unref'ing, and free'ing.
- Date: 01 May 2000 11:54:08 -0400
David Allen <s2mdalle@titan.vcu.edu> writes:
> What is the correct way to get rid of a style once you're finished
> with it? I noticed in the gtk source code that gtk_style_copy and
> most of the others call gtk_style_new which allocates new memory with
> g_new0 as one of the first things it does. It stands to reason then
> that it would need to be g_free'd when the programmer is done with it.
>
> But when I use gtk_style_unref() and g_free(some_style) I end up
> getting piles of failed assertions (the assertion is style->ref_count
> > 0 I believe).
>
You don't own the right to g_free() the style; you only own a
reference. You should call unref() once for each reference you own,
and nothing else. If you are the last person to unref(), then GTK will
g_free() the style. But you don't need to care when g_free() is
called; simply release your references, and never access the style
unless you know a reference is outstanding.
> Alternatively, is this handled through the widget the style is
> attached to? When the widget gets destroyed, does the style die
> too?
No, the style dies when no references are left.
> If so, then how would it work to set one structure as the style for
> multiple widgets? (Which might die at different times?)
>
Each widget has a reference. When the last widget is gone, if no one
else has a reference, the style dies.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]