How to release memory? (D2.0.30)

BCS none at anon.com
Sat Jul 4 08:35:34 PDT 2009


Hello AxelS,

> BCS Wrote:
> 
>> You can't. The D runtime (and most other runtimes) don't ever reduce
>> the amount of memory they keep in the heap. If you where to allocate
>> another 25MB right after that function you would see no change in the
>> memory usage. The good news is that with virtual memory, all of that
>> has almost zero cost. What matters is how much ram you are actively
>> using.
>> 
> I want to load and send a file via network...when I load the entire
> file into memory it's very stupid that I can't release that memory
> again...
> 
> OK I'll try it with the C API but thanks for your help!
> 

C's runtime (malloc/free) doesn't return memory to the OS either. Unless 
your system starts complaining about wanting to make the swap file bigger, 
quit worrying about it.

OTOH another way to work this is to memory map the file and unmap it when 
you are done. That way the original file is used as the backing store rather 
than the swap file and the memory gets unmapped when you dump the file.




More information about the Digitalmars-d-learn mailing list