Re: gtk_object_sink in glade_palette_init



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Nov 28, 2006 at 09:44:54AM +0100, Philippe Bertin wrote:
Hello,

[...] But what I actually meant to ask, is : what's the use of 
first adding a reference, (because that's what's happening in my eyes), 
for removing the reference /just the statement after/. Because that's 
what's happening in my understanding.

Not quite...

[...]

In glade_palette_init, there's this piece of code :

   /* Add items tray (via a scrolled window) */
   priv->tray = gtk_vbox_new (FALSE, 0);
   g_object_ref (G_OBJECT (priv->tray));
   gtk_object_sink (GTK_OBJECT (priv->tray));

AFAIU, after the _new() the box has a special reference to it: the ref
count is one, but it is marked as "floating"[1]. Now gtk_object_sink()
decrements the ref coung by one *only* if the object is marked as
floating and does nothing otherwise. So the net effect of this code is
to clear the floating flag. See for example

  <http://developer.gnome.org/doc/GGAD/z57.html>

for an explanation.

- ------------
[1] What this means in terms of practical consequences isn't quite clear
to me (perhaps some guru cares to give a pointer), but the idea is to
keep a ref to an yet-unused object you don't want to disappear from
under you before you've put it safely somewhere. Think of it as "half
referenced".

Note that putting the object in a container or whatever sinks() it and
that leads to quite natural code without ref leaks.

Regards
- -- tomÃs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFa/u4Bcgs9XrR2kYRAiDMAJ9el81E+fMjdig32fL0o0VRs6BfLgCfVRnR
Oj4ItExvKQVQfxrN522Zf8Y=
=1htW
-----END PGP SIGNATURE-----




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