On Thu, March 4, 2010 13:23, Phil Housley wrote:
> On 3 March 2010 23:17, Jan Hudec <[email protected]> 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.

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 <[email protected]>

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to