I was playing around with some code today and I noticed that in
some cases struct destructors are not called.
for example:
impost std.stdio;
SomeStruct global;
void main()
{
SomeStruct inMain;
writeln(global.thing);
writeln(inMain.thing);
writeln(getSomeInt());
}
int getSomeInt()
{
static SomeStruct inner;
return inner.thing;
}
struct SomeStruct
{
int thing = 100;
~this()
{
writeln("destructor");
}
output is
100
100
100
destructor
Only inMain's destructor is ever called, or at least it is the
only one that ever prints "destructor" to the console. Are there
special rules for structs that I'm unaware of?