Re: [Vala] Does vala provide syntactic sugar for "weak" references that know when its peer has been nulled?



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 reference
coutning or copying that you have to be careful with and can do without. Full
weak references are obviously useless for that, since setting up the back
link is more expensive than the reference counting in the first place.

Just for the record, Java does have various reference types, including weak.

For a summary: http://java.sun.com/javase/6/docs/api/java/lang/ref/package-summary.html
For some classes:
http://java.sun.com/javase/6/docs/api/java/lang/ref/Reference.html

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.

-- 
Phil Housley



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