1
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?
1
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?
1
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.
3
Yes. 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.
if the RAM is reclaimed, why is it that first opening a program (eg IE or Opera or FireFox etc) it usually takes some time but after I've closed it and waited 10 minutes, and open it again it is much much faster compared to the first time? – Pacerier – 2011-07-31T23:02:18.927
Even though the physical RAM is freed up, most modern operating systems are smart about caching files often used, or used together. These files might be left in the page file or some other structure for easier load time. For example, you'll see a bigger benefit when the OS can pre-determine that it will need, say, 5 files at once (a.exe, b,dll, c.dll), instead of relying on the normal behavior (page faults) to load them on demand. The information will still need to be paged from disk to RAM, but will be better optimized to frontload necessary files and to avoid seeking around the hard disk. – Jimmy – 2011-07-31T23:53:29.677
Jimmy, can you show where in Process Explorer? – barlop – 2011-08-28T22:04:59.797
@barlop: In the System Information window, which can be reached by clicking on any of the performance graphs (CPU/RAM/IO) or from the View menu. – Jimmy – 2011-08-28T23:50:36.537
@Jimmy I don't see any bits getting zeroed out, just a graph, and if I close a big process, or a bunch like taskkill /f /im chrome.exe I see the numbers go down for System commit and physical memory which is nothing special one would see similar with task manager, but no change in the graphs, and certainly no bits getting zeroed out. – barlop – 2011-08-29T01:44:49.887
@barlop - it might be that your computer is zeroing out the pages so quickly that they don't show up in Free pool. Is the Zeroed pool growing as you close your apps? – Jimmy – 2011-08-29T02:59:44.350
@Jimmy I think I see how it does it and thus what you mean. If I don't close any app, the graph "grows" and "grows" with time without rising or dipping eventually reaches the entire screen and only clears when I close and reopen process explorer, moving the mouse also shows the x axis represents time hence the "growth" by the second without rising or dipping. If I close a big app like chrome, it dips, if I reopen it, it rises somewhat. Nothing as exciting as seeing the memory locations bits getting zeroed out though! – barlop – 2011-08-29T13:47:30.967
in the Task Manager (i'm windows vista) there is a place that show us the "Memory". Does this memory coincides with the first RAM that you were talking about or the second RAM that you were talking about? – Pacerier – 2011-08-29T07:02:01.493
There are actually several "memory" fields in the task manager, but they don't correspond to either of these because while the program is running, there isn't a difference. (And generally, file data resident isn't cache isn't accounted for by process anyway. Consider if 8 copies of a program are running. Do you charge the executable to all of them?) – David Schwartz – 2011-08-29T12:01:17.057