D - gc: a few strange things, possibly bugs
- Sark7 (39/39) Apr 25 2004 1)
1) [code] class A { B b; this() { printf("A"); b = new B(); } ~this() { printf("a"); } } class B { this() { printf("B"); } ~this() { printf("b"); } void foo() {}; } void main() { A a = new A(); } [/code] outputs: ABba A keeps reference for B, then why B dtor is called first? And any access to B members in A dtor (for example foo() } causes access violation. 2) [code] class A { this() { printf("A"); B.b = new B(); } ~this() { printf("a"); B.b = null; } } class B { static B b; this() { printf("B"); } ~this() { printf("b"); } } void main() { A a = new A(); // B.b = null; } [/code] outputs: ABa So B dtor is never called, although I set B.b to null in A dtor. But if uncomment last line, B dtor is called. Any ideas? Is it bugs?
Apr 25 2004