Using the delete Keyword /w GC

Baz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 25 18:16:29 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?

Until custom class de/allocators are not >>really<< deprecated, 
the delete keyword is not >>necessarly<< deleting from the GC. 
Look at this:

http://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation

You can do the same but without adding the class reference to the 
GC. Then delete will call the custom deallocator which is itself 
not calling the GC.

So in a way I think you're right when you say that delete could 
help into manual mem managment. But that's not a reliable (over 
time) situation.



More information about the Digitalmars-d-learn mailing list