Memory usage isn't decreasing when using free?

后端 未结 3 1867
时光说笑
时光说笑 2020-12-21 12:47

Somehow this call to free() is not working. I ran this application on Windows and followed the memory using in Task Manager, but saw no reduction in memory usag

相关标签:
3条回答
  • 2020-12-21 13:03

    Note that the Task manager will show the memory "borrowed" by libc from the system. But not all mallocs will go through libc to the operating system and similarly not all free will free the system memory.

    Usually, libc will allocate memory in larger chunks to supply for several malloc calls.

    0 讨论(0)
  • 2020-12-21 13:08

    You can not assume that just after doing the free the memory will be returned back to OS. Generally the CRT implementation have some optimization because of which they may not return this memory immediately. This allows the CRT to allocate the subsequent memory allocation requests in a faster way.

    0 讨论(0)
  • 2020-12-21 13:10

    Typical C implementations do not return free:d memory to the operating system. It is available for use by the same program, but not to others.

    0 讨论(0)
提交回复
热议问题