Re: g_object_ref_sink and GUnowned

On Mon, 2006-01-02 at 08:55 +0800, James Henstridge wrote:

> This sounds a lot more sensible than a new class.  If some
> non-constructor function gives you a GObject, the distinction between a
> GObject and GUnowned doesn't tell you anything -- it only tells you
> about initial conditions.
> Also, modelling the state of the initial reference through inheritance
> doesn't seem to account for GtkWindow and its subtypes, which derive
> from GtkObject (which would be a GUnowned subclass), but don't start
> with a single floating reference to begin with.

However, you can't just turn on a "is a normal GObject" flag for

 window = gtk_window_new();

Is a bug (and I think even double-unrefs). GtkWindow's are created
owning their own refcount, which they unref on ::destroy. (Alternatively
you can think of the refcount being held by the global list of
windows accessed by gtk_window_list_toplevels())

A GtkWindow should be handled just like any other GtkObject from
a language binding.

 window = gtk_window_new ();
 g_object_ref (window);
 gtk_object_sink (window);

 [... use the window, time passes...]

 g_object_unref (window);

(Prior to recent changes. Mutatis mutandis.)


Attachment: signature.asc
Description: This is a digitally signed message part

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