Re: weakref semantics



Tim Janik wrote:
On Thu, 17 Jan 2008, Alexander Larsson wrote:

On Wed, 2008-01-16 at 15:03 +0000, jcupitt gmail com wrote:
I noticed the weakref introduction says that notifies can be called many times:

http://library.gnome.org/devel/gobject/unstable/gobject-memory.html#gobject-memory-weakref

   ... which is invoked when the object runs its dispose method. As such,
   each weak ref can be invoked more than once upon object finalization
   (since dispose can run more than once during object finalization).

I'm not sure this is right: looking at the source for gobject it seems
that the notifies are a fire-once thing, and are removed upon firing.

Should I open a docs bug on this? (or am I confused?)

you mis the facts that new weak refs can be added at any point in time,
such as after dispose, in finalize or even during weakref notifies.
(that's actually the semantics of GObject's GData mechanism which
is used to implement weakrefs)

I actually have a related question. I remember that weak refs weren't
allowed to ressurect the object. However, with the weak ref callbacks
running from dispose, and dispose being allowed to ressurect the object,
why can't weak refs ressurect?

because weakrefs will also run during finalization, and an object
can not be resurrected from finalization.

Maybe weak ref callbacks should be moved to finalization?

conceptually yes. regarding backwards compatibility, no.

Then there is another docs bug, g_object_weak_ref()
docs say:

A GWeakNotify <cid:part1.03020602.08010607@tamu.edu> function can be added to an object as a
callback that gets triggered when the object is finalized.
Since the object is already being finalized when the
GWeakNotify <cid:part1.03020602.08010607@tamu.edu> is called, there's not much you could do with
the object, apart from e.g. using its adress as hash-index or the like.

I have never seen the docs quoted in the original mail,
and what docs say about g_object_weak_ref() implies
that weak ref callback is called 1) exactly once; 2) after
the object is finalized (and so I got some code which
supposes that the callback is called exactly once). So
what is the truth? Possibly more than once, and before
finalize()?

Best regards,
Yevgen



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