www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does D's GC release memory back to the OS?

reply Richard White <rwhite226 gmail.com> writes:
Just wondering if D's GC release memory back to the OS?
The documentation for the GC.minimize 
(http://dlang.org/phobos/core_memory.html#.GC.minimize) seems to 
imply that it does,
but watching my OS's memory usage for various D apps doesn't 
support this.
Oct 24 2015
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Sunday, October 25, 2015 05:49:42 Richard White via Digitalmars-d-learn
wrote:
 Just wondering if D's GC release memory back to the OS?
 The documentation for the GC.minimize
 (http://dlang.org/phobos/core_memory.html#.GC.minimize) seems to
 imply that it does,
 but watching my OS's memory usage for various D apps doesn't
 support this.
It is my understanding that the GC does not normally ever return memory to the OS (though it's been worked on quite a bit over the last couple of years, so that may have changed - probably not though, since that wouldn't really help memory performance and could actually hurt it). minimize's documentation clearly indicates that it returns memory to the OS, but that doesn't necessarily mean that the GC ever does that on its own. It just means that the GC provides a way for the programmer to tell it to return memory to the OS. And I would guess that calling minimize frequently would harm performance. It probably mostly makes sense after you know that your program has used a lot of memory for something and isn't going to need that memory again. But the functions in core.memory are intended for performance tweaking for the adventurous and/or those who really need to tweak performance as opposed to something that a typical program would do. - Jonathan M Davis
Oct 25 2015
parent reply Cauterite <cauterite gmail.com> writes:
On Sunday, 25 October 2015 at 08:56:52 UTC, Jonathan M Davis 
wrote:
 It is my understanding that the GC does not normally ever 
 return memory to the OS
It seems that it does now. In smallAlloc() and bigAlloc(), if allocation fails it collects garbage and then: if (lowMem) minimize(); On Windows, lowMem is calculated with GlobalMemoryStatus(), and is true if "Less than 5 % of virtual address space available" This is hardly ideal, but better than nothing I guess.
Oct 26 2015
parent Cauterite <cauterite gmail.com> writes:
Correction: you said
"the GC does not normally ever return memory"
and you're right, because applications do not "normally" consume 
95% of their address space.
Oct 26 2015