Why is "delete" unsafe?

Jonathan M Davis jmdavisProg at gmx.com
Fri Oct 26 18:07:42 PDT 2012


On Friday, October 26, 2012 16:12:15 H. S. Teoh wrote:
> The problem is that you can call delete on GC'd objects, which in some
> cases causes bad interaction with the GC. That's why it has been
> deprecated.
> 
> The intention was never to get rid of manual memory management. It was
> to prevent unsafe interactions with the GC. If you don't want to use the
> GC, use malloc(), free(), and emplace. (In fact, this way you can have
> *both* GC and manual memory management. The emplace()'d objects will be
> manually managed, and the others will be collected by the GC.)

Exactly. In general, you should do manual memory management with memory that 
is manually allocated and _not_ with memory which is GC-allocated (which is 
where delete goes wrong).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list