The "@safe vs struct destructor" dilemma

deadalnix deadalnix at gmail.com
Sat Apr 12 02:01:12 PDT 2014


On Saturday, 12 April 2014 at 03:02:56 UTC, Michel Fortin wrote:
> 2- after the destructor is run on an object, wipe out the 
> memory block with zeros. This way if another to-be-destructed 
> object has a pointer to it, at worse it'll dereference a null 
> pointer. With this you might get a sporadic crash when it 
> happens, but that's better than memory corruption. You only 
> need to do this when allocated on the GC heap, and only 
> pointers need to be zeroed, and only if another object being 
> destroyed is still pointing to this object, and perhaps only do 
> it for @safe destructors.

You don't get a crash, you get undefined behavior. That is much 
worse and certainly not @safe.


More information about the Digitalmars-d mailing list