Using the delete Keyword /w GC

Brad Anderson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 25 10:20:19 PDT 2014


On Monday, 25 August 2014 at 17:10:11 UTC, Etienne wrote:
> People have been saying for quite a long time not to use the 
> `delete` keyword on GC-allocated pointers.
>
> I've looked extensively through the code inside the engine and 
> even made a few modifications on it/benchmarked it for weeks 
> and I still can't see why it would be wrong. Wouldn't it help 
> avoid collections and make a good hybrid of manual 
> management/collected code? The free lists in the GC engine look 
> quite convenient to use. Any ideas?

delete was deprecated because it is memory unsafe (there may 
still be references to the memory). You can still use GC.free() 
to free the memory but it must only be used with care.

I feel if you are managing delete yourself you might as well 
manage allocation yourself too and take pressure off the GC. If 
you are sure you have only one reference and GC.free() is safe, 
Unique was probably a better choice anyway.


More information about the Digitalmars-d-learn mailing list