开发者

In Win32, HeapFree doesn't return the memory

开发者 https://www.devze.com 2023-03-08 16:31 出处:网络
I have tested about HeapAlloc and HeapFree in Win32 c++. I have created private heap with HeapCreate(0,0,0).

I have tested about HeapAlloc and HeapFree in Win32 c++.

I have created private heap with HeapCreate(0,0,0).

Next, I have alloced 100KB with HeapAlloc(_heaphandle, 0, 1024*100).

The process memory increased about 100KB with some overhead. I have checked this process memory with "process tab of windows work manager".

I have alloced 100KB some times. So, I have got following result.

process memory : 1,312KB  committed:3472, uncommitted:25804开发者_Python百科8, alloced: 0

process memory : 1,420Kb  committed:7544, uncommitted:151552, alloced: 102400

process memory : 1,524Kb  committed:11616,uncommitted:45056,  alloced: 204800

process memory : 1,632KB  .............                       alloced: 307200

process memory : 1,736KB  .............                       alloced: 409600

Next, I have freed memory with HeapFree(_heaphandle, 0, pointer).

But, the process memory doesn't return memory. I'm really curious when the process memory free.

I have got following result:

process memory : 1,736KB  committed:23744, uncommitted:876544, alloced: 409600

process memory : 1,736Kb  committed:126152,uncommitted:876544, alloced: 307200

process memory : 1,736Kb  committed:228592,uncommitted:876544, alloced: 204800

Finally, I have destroyed private heap with HeapDestroy(heaphandle). then, all heap memory free.

The Process memory goes to initial value 1,312KB.

If I use many memory, I am concerned to suffer from lack of memory.


You won't suffer from lack of memory. When you do HeapFree the HeapManager may not actually release it back to the OS and might keep it for future allocations. So when the next time you do HeapAlloc it can allocate from that memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消