The question is a lot similar to Will malloc implementations return free-ed memory back to the system?, but I am interested about an answer for Windows / Microsoft Visual Studio, and about details on the exact virtual memory state.
Will Visual C++ CRT free return the memory back to the system? What will be the exact state of the memory in respect to virtual memory allocations? After doing free on a large memory block, will the memory in the block be committed, reserved, or free? What if I call _heapmin after the free?
Inspecting the source code for 2010, it can be seen malloc/free call HeapAlloc/HeapFree Win32 API functions directly, with a _crtheap as a heap created by the runtime. The answer for VS 2010 and recent Windows versions (Win2000, WinXP, Vista, Win 7) therefore is:
The memory returned by the free is returned to OS, but it stays committed.
Heap Functions documentation says following regarding how is the memory commitment handled:
Moreover, HeapCreate documentation says following regarding the case of a heap with no maximum size set:
I did not find anything which would say whether those block allocated using VirtualAlloc are handled in a special way when released, an experiment would probably be needed to know this.
As for _heapmin, with VS 2010 is does nothing, as it only calls HeapCompact and the CRT heap does not have automatic coalesce on free turned off. The documentation for _heapmin, therefore, seems wrong, most likely a relic from some old version of the runtime.