Manually freeing up memory

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Nov 7 10:56:35 PST 2012


On 11/07/2012 06:53 PM, H. S. Teoh wrote:
> I think on Posix systems, malloc/free does not return freed memory back
> to the OS, it just gets reused by the process later on.

I have to say that in this program, it looks like the memory usage keeps 
increasing even after the free(), even though theoretically the amount it's 
possible to free up would dwarf any subsequent memory requirements.

Using GC.missing() seems to return a very little bit of memory to the OS, 
depending on which compiler is used, but nowhere near the amount it's 
theoretically possible to hand back.

> An easier workaround might be to fork() a process that constructs
> whatever data structures you need, transmits that to the main process
> somehow, then exit. If I understand it correctly, the large memory
> allocations will be restricted to the child process, which will get
> returned to the OS once it exits. (Note that you have to use fork(), not
> threads, because threads share memory in the same process so you end up
> with the same problem.)

Nice thought!  I'll have a look at doing this.



More information about the Digitalmars-d-learn mailing list