Why does destructor of global var isn't called?
Basilez B.
b2.temp at gmx.com
Tue Dec 25 20:46:08 UTC 2018
On Tuesday, 25 December 2018 at 19:32:47 UTC, Dru wrote:
> example:
> -----------
>
> struct A{
> int* arr;
>
> ~this() {
> writeln("A destruct");
> }
> }
>
> static ~this() {
> writeln("module destruct");
> }
>
> A a;
>
> void main() {
> }
>
> -----------
>
> only prints "module destruct"
`a`, since declared in the global scope, is constructed at
compile-time so its data are in executable dedicated segments
(althoufh here it's just equal to A.init) and don't have to be
destructed. Add `a = A(null); ` in main and the destructor gets
called.
More information about the Digitalmars-d
mailing list