Re: weakref semantics



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.

---
ciaoTJ


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