Memory issues. GC not giving back memory to OS?

Arafel er.krali at gmail.com
Wed Apr 22 07:46:50 UTC 2020


On 21/4/20 22:23, Jonathan M Davis wrote:
> On Tuesday, April 21, 2020 12:31:28 PM MDT Cristian Becerescu via
> Digitalmars-d wrote:
>> This is a bit odd, because 1.107 * 2^30 is roughly 4.4GB, and the
>> peak memory consumption was 7GB. Apparently, the GC can correctly
>> collect the memory when manually calling collect() at the end of
>> appending, but that memory (we are talking 7 - 4.4 = 2.6GB) is
>> never given back to the system. At least this is our intuition
>> after making those observations.
> 
> It is my understanding that under normal circumstances, the GC will never
> return memory to the OS until the program terminates but rather will just
> keep it around to reuse when more memory needs to be allocated. However, the
> documentation for core.memory's GC.minimize says that it will return free
> memory to the OS. So, if you need memory to be returned to the OS while the
> program is running, you'll probably need to use that.
> 
> - Jonathan M Davis
> 
> 
> 

I had a similar issue some time ago, and found that the memory wouldn't 
be returned to the OS even after the GC had freed it. I had to call 
malloc_trim [1] manually, this seems to be a libc / OS issue (I'm 
exclusively using linux, I don't know if this is also an issue with 
Windows or Mac).

Could this be also happening here?

A.

[1]: http://man7.org/linux/man-pages/man3/malloc_trim.3.html


More information about the Digitalmars-d mailing list