Why is "delete" unsafe?

Adam D. Ruppe destructionator at gmail.com
Fri Oct 26 16:08:38 PDT 2012


On Friday, 26 October 2012 at 23:03:15 UTC, Minas wrote:
> What is unsafe about it?

If you delete something but keep a reference to it, at some point 
down the line, the memory could be reused.

Then your old reference points to a different type of object and 
could treat it differently.


Just for example:

string code = something;

delete code;

// but oops code is still there and pointing at some memory...

int[] something = new int(10); // this might reuse the memory


eval(code); // now this evals a bunch of ints as if they were 
code which certainly isn't what you expected



More information about the Digitalmars-d-learn mailing list