Re: [Vala] Does vala provide syntactic sugar for "weak" references that know when its peer has been nulled?
- From: "Jan Hudec" <bulb ucw cz>
- To: "Phil Housley" <undeconstructed gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Does vala provide syntactic sugar for "weak" references that know when its peer has been nulled?
- Date: Fri, 5 Mar 2010 14:05:13 +0100 (CET)
On Thu, March 4, 2010 13:23, Phil Housley wrote:
On 3 March 2010 23:17, Jan Hudec <bulb ucw cz> wrote:
On Wed, Mar 03, 2010 at 15:22:59 -0600, Sandino Flores Moreno wrote:
Is it possible for a weak ref to know when its peer object has been
deleted (and then assigned to null)?
By the way, note that Java and C# don't have any weak references at all.
Unowned references in vala are mostly optimization to avoid some
coutning or copying that you have to be careful with and can do without.
weak references are obviously useless for that, since setting up the
link is more expensive than the reference counting in the first place.
Just for the record, Java does have various reference types, including
For a summary:
For some classes:
Reference.get() is the safe way to get a referenced object - assigning
the result to something strongly references the object and so it is
safe for as long as you need it.
Sorry, I seem to have forgotten how weak references are really intended to
work. I mistook the fact it does not have any language-level support for
them for not having them at all.
Obviously it should be possible to implement weak references for Vala in
the same way. No syntactic sugar is needed and it does not even make sense.
A Reference class for Vala can be implemented via GLib.Object.weak_ref and
GLib.Object.weak_unref. It needs to involve a lock, too and, because how
the GLib.Object.unref is implemented it may happen that if you resurrect
the object in the last moment (when it's about to be removed), some weak
references may already be cleared.
- Jan Hudec <bulb ucw cz>
] [Thread Prev