allocate array with new

Jonathan M Davis jmdavisProg at gmx.com
Wed May 16 09:52:33 PDT 2012


On Wednesday, May 16, 2012 11:51:59 Steven Schveighoffer wrote:
> Well, the D GC is conservative, and will always be at least partly
> conservative. So freeing memory manually is not really a crime.

The idea with a GC is that it's supposed to manage the memory allocated 
through it. So, if you're worrying about freeing GC memory, you're fighting the 
GC and how it works. And unless you're keeping very close track of the number 
of reference to a particular chunk of memory, freeing it manually is 
dangerous. So, anyone looking to use delete is generally going about things 
the wrong way.

However, it _is_ true that sometimes you need to intervene in order to get 
sections of code as performant as they need to be (particularly since D's 
current GC is not the most performant), which is part of the reason that 
core.memory provides what it does. But it should generally be something used 
when it's clear that you need that extra performance, not as a matter of 
course, because using it is inherently unsafe. If there's something that you 
know ahead of time needs to have more deterministic deallocation, then it's 
probably better to be use malloc and free with ref-counting than trying to 
manually manage GC memory.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list