tlsgc_sections.d revision 1.1.1.1
1final class Class 2{ 3 // This gets triggered although the instance always stays referenced. 4 ~this() 5 { 6 import core.stdc.stdlib; 7 abort(); 8 } 9} 10 11Class obj; 12 13static this() 14{ 15 obj = new Class; 16} 17 18static ~this() 19{ 20 // Free without destruction to avoid triggering abort() 21 import core.memory; 22 GC.free(cast(void*)obj); 23} 24 25void doit() 26{ 27 foreach (i; 0 .. 10_000) 28 new ubyte[](100_000); 29} 30 31void main() 32{ 33 import core.thread; 34 auto t = new Thread(&doit); 35 t.start(); 36 37 // This triggers the GC that frees the still referenced Class instance. 38 doit(); 39} 40