Does Windows reclaim RAM right after a process quits?
Matthew Harrington
When we quit a process (e.g. using Task Manager etc), Does Windows reclaim the RAM used immediately?
Or does Windows still retain the RAM used for that process?
2 Answers
I depends what RAM you mean. If you mean any RAM containing data modified by the process, then yes. Those values could never, ever be used again. So the RAM must be marked free.
If you mean RAM containing portions of the executable file, no, that RAM is not reclaimed. It was already marked discardable, since the system can always read the data back from disk if needed anyway. Freeing the RAM immediately would suck for two reasons:
1) It's a completely wasted effort. If the computer makes the RAM free and it isn't needed soon, the effort of making it free gained nothing. If the computer makes the RAM free and it is needed soon, the effort of making it free just forces the system to make it used again, resulting in doubled effort. (The system could just have left it discardable and switched it to another use without ever making it free.)
2) It deprives the system of the opportunity to use that data again. If the same program runs again, having the data already in RAM saves disk I/O.
2Yes. The memory pages are re-assigned into the Free pool, where they can be allocated to new processes on demand. A very-low priority process in the OS will eventually zero out those pages, adding them to the Zeroed pool. You can watch this going on with Process Explorer (though they get zeroed out fast enough it's hard to see).
Pages of memory in either of these pools are free for the taking for existing or new processes. Once there are no free pages in either the Free or Zeroed pools, the OS will start to forceably page out memory from other processes to re-use pages of physical RAM as needed. There are 2 sets withing this group: Standby and Modified pages. A Standby page is one that has alread been paged out to the page file and can be re-assigned to a different process (or within the same) quickly. A Modified page has a dirty flag set and needs to be saved to the page file before it can be re-assigned.
7