Will Visual C ++ runtime malloc / free memory return to OS?

The question is very similar to Will the malloc implementation return free memory back to the system? , but I'm interested in the answer for Windows / Microsoft Visual Studio, as well as information about the exact state of virtual memory.

Will Visual C ++ CRT be free to return memory back to the system? What will be the exact state of the memory regarding virtual memory allocation? After free use on a large memory block, will the memory in the block be fixed, reserved or free? What if I call _ heapmin after free?

+5
source share
2 answers

Checking the source code for 2010, you can see the malloc / free call HeapAlloc / HeapFree Win32 API works directly with _crtheap as a heap created by the runtime. Answer to VS 2010 and latest versions of Windows (Win2000, WinXP, Vista, Win 7):

The memory returned by the free is returned to the OS, but it remains committed.

The heap function documentation reports the following about how memory is processed:

HeapCreate , HeapAlloc.... , HeapAlloc , , . , , , , HeapDestroy.

, HeapCreate :

dwMaximumSize 0, . . , , ; VirtualAlloc , . , , dwMaximumSize 0.

, , , VirtualAlloc , , , .

_ heapmin, VS VS , HeapCompact, CRT . _heapmin , , - .

+6

, "". _heapmin , , . . , , , , free() _heapmin . , VS Debug Release.

. API- HeapCreate()/HeapAlloc() ..

+1

All Articles