Debian Codegraph @

src/test/01-Basic/230-dangle-ref-new.ck

raw
1 // verify ref counting for `new` unary operator
2 // NOTE as of 1.5.1.8 `new` always add-ref then release at
3 // end of statement, so if the ref is retained, it will be
4 // properly disposed by statement's end
5
6 // a class
7 class Foo
8 {
9 // member
10 5 => int x;
11
12 // print stuff
13 fun Foo get()
14 {
15 // <<< Machine.refcount( this ) >>>;
16 return this;
17 }
18 }
19
20 // should print 5
21 <<< (new Foo).x, "" >>>;
22
23 // should be 2 ref counts: `new` and get()
24 <<< Machine.refcount((new Foo).get()), "" >>>;