forcing "@nogc" on class destructors

Jerry Morrison via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 27 19:00:36 PST 2015


 From the forum thread 
http://forum.dlang.org/thread/ossuvfmqthllgdpgzntm@forum.dlang.org?page=1

and the PR 
https://github.com/D-Programming-Language/dlang.org/pull/851

I learned that allocation in a destructor isn't the only crash 
case here.

The GC calls a class instance's invariant() method during a 
collection cycle, before calling the object's destructor, and 
possibly after destructing objects it references. So if the 
invariant() touches any of its member references, it can crash!

A solution to that would be to never call invariants during a 
collection cycle, but what other gotcha's exist during 
collection? Would @nogc on class destructors help them?


More information about the Digitalmars-d mailing list