[Vala] Does vala provide syntactic sugar for "weak" references that know when its peer has been nulled?
- From: Sandino Flores Moreno <tigrux gmail com>
- To: vala-list gnome org
- Subject: [Vala] Does vala provide syntactic sugar for "weak" references that know when its peer has been nulled?
- Date: Wed, 3 Mar 2010 15:22:59 -0600
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]