Re: GtkWindow destroy problem



On 6 Sep 2001, Martin Baulig wrote:

> Darin Adler <darin bentspoon com> writes:
> 
> > on 9/5/01 11:42 PM, Tim Janik at timj gtk org wrote:
> > 
> > > not in GtkObject, since this is valid code (apart from GTK_TYPE_OBEJCT
> > > being abstract):
> > > o = g_object_new (GTK_TYPE_OBJECT, NULL);
> > > gtk_object_unref (o);
> > 
> > If anyone other than you tried to tell me this was valid, I would tell him
> > he was wrong.
> > 
> > Havoc has drilled it into my head over the last year that the floating
> > reference cannot be legally removed with unref.
> 
> Ok, so just to make sure I did it right, is the following correct ?
> 
>   o = g_object_new (GTK_TYPE_WINDOW, NULL);
>   gtk_object_ref (o);
>   gtk_object_sink (o);
>   /* ... some time later ... */
>   g_object_unref (o);

not quite. the correct way to control the lifecycle of *any* GtkObject
(note, _g_t_k_object, *not* _g_object) is:

o = g_object_new (GTK_TYPE_*, NULL);
gtk_object_ref (o);
gtk_object_sink (o);

/* do stuff with object, e.g. add/remove to/from containers */

gtk_object_destroy (o);
gtk_object_unref (o);

> 
> -- 
> Martin Baulig
> martin gnome org (private)
> baulig suse de (work)
> 

---
ciaoTJ





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