How to release memory? (D2.0.30)
downs
default_357-line at yahoo.de
Sun Jul 5 02:48:31 PDT 2009
BCS wrote:
> 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.
Um .. yes it does. :)
#include <stdio.h>
#include <stdlib.h>
int main() {
void *p = calloc(1024*1024*256, 1);
system("sleep 10");
free(p);
system("sleep 10");
return 0;
}
Run that, wait 10s, and watch the memory usage go down.
More information about the Digitalmars-d-learn
mailing list