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



Hello.
Is it possible for a weak ref to know when its peer object has been
deleted (and then assigned to null)?

Because, suppose you have a weak reference, then the real object is deleted.
So your "weak reference" should be notified, otherwise you might get segfaults.

Something to better write the following code:



class Test: Object {
        public int i {get; set;}
        construct {
                i=1;
                print("Constructing instance\n");
        }
        ~Test() {
                i=0;
                print("Finalizing instance\n");
        }
}

void main() {
        Test t = new Test();
        Test **tr = &t;
        print("t = %p %d\n", t, t.i);

        if(*tr != null)
                print("tr = %p %d\n", tr, (*tr)->i);
        else
                print("Peer object has been deleted\n");

        t=null;

        if(*tr != null)
                print("tr = %p %d\n", tr, (*tr)->i);
        else
                print("Peer object has been deleted\n");
}



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