here is a simple d / tango code in windows:
module d_test.d;
import tango.util.log.Trace;
import tango.core.Thread;
import tango.stdc.stdlib : malloc, free;
void main() {
Trace.formatln("Checking in...");
Thread.sleep(10);
int total_n = (100 * 1000 * 1000) / int.sizeof;
int* armageddon = cast(int*)malloc(total_n * int.sizeof);
for(int i = 0; i < total_n; ++i) {
armageddon[i] = 5;
}
Trace.formatln("Checking in...");
Thread.sleep(10);
free(armageddon);
armageddon = null;
Trace.formatln("Checking in...");
Thread.sleep(10);
}
when I run the program, the memory remains low ~ 2 MB, and when I allocate an array of 100 MB to use the pointer memory up to ~ 100 MB, this is normal. However, after the free memory is still (I look at the task manager) at 100 MB until the end of the program.
I thought it could be a windows file cache or something else, so I tried a simple C ++ program:
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
Cout << "Checking in..." <<< endl;
Sleep(10000);
int total_n = (100 * 1000 * 1000) / sizeof(int);
int* armageddon = (int*)malloc(total_n * sizeof(int));
for(int i = 0; i < total_n; ++i) {
armageddon[i] = 5;
}
Cout << "Checking in..." <<< endl;
Sleep(10000);
free(armageddon);
armageddon = NULL;
Cout << "Checking in..." <<< endl;
Sleep(10000);
return 0;
}
I compiled it with g ++ and everything works as it should. When the program starts, the memory usage is ~ 900 kb, after allocation ~ 100 MB, after the free ~ 1.2 MB ...
So what am I doing wrong or is this a mistake?
source
share