I am experiencing a weird memory problem. The process in which my C++ application executes consumes both virtual and physical memory as it time progresses.
When I shut down the process, whatever virtual memory that it consumes is returned to the system. However, most of the physical memory that is consumed is never returned to the system. I can view this in Task Manager.
Any memory that my application dynamically allocates should be returned to the system when its process terminates.
The only suspect computations that my application is doing is repeatedly calling FindFirstFile/FindNextFile to examine some existing files in the file system. The operation examines about 10 million files in total. In this case, I believe that I am correctly closing the file handle returned by FindFirstFile.
Can anyone speculate as to why the physical memory is not being returned to the system?
The physical memory is always under the control of the OS. Whatever tool you are using to measure physical memory usage is misleading you.
Possibly the disk cache is growing, possibly the low priority background thread that zeros free pages is not keeping up and your tool treats "free but dirty" differently from "free and zeroed for reuse".
It's also possible that your application is triggering a memory leak in some driver or another process that hasn't exited yet.
In no case is your application continuing to own physical memory after it terminates.