dev/vala/hello/memory.vala

31 lines
591 B
Vala

class Node : Object {
public Node prev;
public weak Node next;
public Node (Node? prev = null) {
this.prev = prev; // ref
if (prev != null) {
prev.next = this; // ref
}
}
}
/*
void main () {
var n1 = new Node (); // ref
var n2 = new Node (n1); // ref
// print the reference count of both objects
stdout.printf ("%u, %u\n", n1.ref_count, n2.ref_count);
} // unref, unref
*/
void main () {
while (true) {
var n1 = new Node ();
var n2 = new Node (n1);
Thread.usleep (100);
}
}