Dealing with GInitiallyUnowned



GInitiallyUnowned was added in glibmm 2.10 to provide some of the weird
refcounting behaviour that GtkObject has in C:
http://developer.gimp.org/api/2.0/gobject/gobject-The-Base-Object-Type.html#GInitiallyUnowned.

It derives from GObject but makes it easy for C coders to give a
newly-created instance to a container without doing manual referencing
and unreferencing. But that's awkward for us because RefPtr expects
normal reference-counting.

Some libraries have started to use this. For instance, clutter and
libccc, so we needed to deal with it.

In glibmm's svn trunk I have added the _DERIVES_INITIALLY_UNOWNED macro
which you can use after _CLASS_GOBJECT() to generate some extra code in
your generated constructors to make these GObjects behave normally
again. Here is an example:
http://svn.gnome.org/viewvc/gnomemm/cluttermm/trunk/clutter/src/actor.hg?view=markup

For hand-coded constructors, you can use the _INITIALLY_UNOWNED_SINK
macro. You should already be using the _CONSTRUCT() macro for these.

I see no need for an actual Glib::InitiallyUnowned class.

I will add this to the gmmproc appendix in the gtkmm book when we are
sure that it is correct:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/aph.html

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com



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