E
Eric Nicolas
Hi,
I am just checking malloc/free behaviour. I thought that if I
properly do one free() for each malloc()-ed block, the memory
can actually be given back to the operating system. At least
it is the case usually under Unix.
Under Windows 2000, with Visual C++ 7 (.Net), I found that it
is not the case : if I allocate many small blocks and then free
them all, the total memory is not given back to the operating
system.
Below is my simple test program. If I look at the total virtual
memory footprint, I see:
- at start : 11 Mo
- after alloc : 145 Mo
- after free : 145 Mo, and it never goes back to 0.
Anyone can explain me why ?
Anyone has an idea how to give back memory to the operating
system after having freed() all the blocks ? I have also tried
a call to _heapmin(), with no more success.
Please answer me on <[email protected]>
-------------------------------------------------------
#include <windows.h>
#include <vector>
#define N 100000
#define S 1000
int main()
{
MessageBox(NULL, "Allocation...", "Test Program", MB_OK);
{
std::vector<void*> list;
for(int i=0; i<N; ++i) list.push_back(malloc(S));
MessageBox(NULL, "Free...", "Test Program", MB_OK);
for(int i=0; i<N; ++i) free(list);
} // This closing brace also frees the std::vector<>
MessageBox(NULL, "Done", "Test Program", MB_OK);
}
I am just checking malloc/free behaviour. I thought that if I
properly do one free() for each malloc()-ed block, the memory
can actually be given back to the operating system. At least
it is the case usually under Unix.
Under Windows 2000, with Visual C++ 7 (.Net), I found that it
is not the case : if I allocate many small blocks and then free
them all, the total memory is not given back to the operating
system.
Below is my simple test program. If I look at the total virtual
memory footprint, I see:
- at start : 11 Mo
- after alloc : 145 Mo
- after free : 145 Mo, and it never goes back to 0.
Anyone can explain me why ?
Anyone has an idea how to give back memory to the operating
system after having freed() all the blocks ? I have also tried
a call to _heapmin(), with no more success.
Please answer me on <[email protected]>
-------------------------------------------------------
#include <windows.h>
#include <vector>
#define N 100000
#define S 1000
int main()
{
MessageBox(NULL, "Allocation...", "Test Program", MB_OK);
{
std::vector<void*> list;
for(int i=0; i<N; ++i) list.push_back(malloc(S));
MessageBox(NULL, "Free...", "Test Program", MB_OK);
for(int i=0; i<N; ++i) free(list);
} // This closing brace also frees the std::vector<>
MessageBox(NULL, "Done", "Test Program", MB_OK);
}