On Mon, 29 Apr 2013 16:36:03 +0200, Andrew Stark <
ast...@gmx.at>
wrote:
>
>How can i free such memory so that GetProcessMemUsage() or apps like
>taskmgr can show the right value? Is this possible or do i have to
>write my own memory-handler to get the right (real) used memory?
The point of using the OS memory management is to allow the system to
determine how much memory to allocate to your process based on it's
demands. If you want to know how much memory you have allocated and
freed you should probably keep a global counter and add/subtract the
malloc'd/freed bytes as you run.
The critical metric is the process working set, this is what the OS
memory allocator is concerned with. It's going to increase your
working set on demand but it's going to be lazy about decreasing your
working set in anticipation of more demand. It's more efficient to be
lazy about freed memory than to be constantly trying to keep everyone
lean.
You can persuade the OS to lean out your process working set with the
EmptyWorkingSet API function.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682606(v=vs.85).aspx