Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 25, 2015 Does D's GC release memory back to the OS? | ||||
---|---|---|---|---|
| ||||
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. |
October 25, 2015 Re: Does D's GC release memory back to the OS? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard White | 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
|
October 26, 2015 Re: Does D's GC release memory back to the OS? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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.
|
October 26, 2015 Re: Does D's GC release memory back to the OS? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cauterite | 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. |
Copyright © 1999-2021 by the D Language Foundation