destructors and GC again

Jarrett Billingsley kb3ctd2 at
Mon Oct 16 19:05:48 PDT 2006

"Derek Parnell" <derek at> wrote in message 
news:1iii9n8i8lu91.pvgnflxb8mfc$.dlg at

> What do you mean? Doesn't "global" mean that the variable needs to be
> accessible until main() (or any module dtor for the 'main' module) exits?

If "A tmp" is declared at global scope, writing "auto tmp = new A" in main() 
will not initialize it.  It makes a local variable named "tmp" whose type is 
automatically deduced.  Unless that's not what you were getting at at all..

> Thus this is also okay ...
>  static ~this() { delete tmp; }

Yes, that works well.  That's basically what I do to free any and all 
globally held resources (or those which are static members of classes, which 
are held in the same data segment I guess). 

More information about the Digitalmars-d-learn mailing list