在Win32中,HeapFree不返回内存
我已经在 Win32 c++ 中测试了 HeapAlloc 和 HeapFree。
我已经使用 HeapCreate(0,0,0)
创建了私有堆。
接下来,我使用 HeapAlloc(_heahandle, 0, 1024*100)
分配了 100KB。
进程内存增加了约 100KB,并产生了一些开销。 我已经使用“Windows 工作管理器的进程选项卡”检查了该进程内存。
我有几次分配了100KB。 所以,我得到了以下结果。
process memory : 1,312KB committed:3472, uncommitted:258048, 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
接下来,我使用 HeapFree(_heahandle, 0,pointer)
释放了内存。
但是,进程内存不会返回内存。我真的很好奇进程内存何时释放。
我得到以下结果:
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
最后,我用 HeapDestroy(heahandle) 销毁了私有堆。 然后,所有堆内存都释放。
进程内存变为初始值 1,312KB。
如果我使用很多内存,我担心会出现内存不足的情况。
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:258048, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不会因为缺乏记忆而痛苦。当您执行HeapFree时,HeapManager实际上可能不会将其释放回操作系统,并可能保留它以供将来分配。因此,当您下次执行
HeapAlloc
时,它可以从该内存中进行分配。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 doHeapAlloc
it can allocate from that memory.