The "@safe vs struct destructor" dilemma

Kagamin spam at here.lot
Sat Apr 12 03:29:50 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.

Other objects will have a valid pointer to zeroed out block and 
will be able to call its methods. They are likely to crash, but 
it's not guaranteed, they may just fine corrupt memory. Imagine 
the class has a pointer to a memory block of 10MB size, the size 
is an enum and is encoded in the function code (won't be zeroed), 
the function may write to any region of that block of memory 
pointed to by null after the clearing.


More information about the Digitalmars-d mailing list