kirkmc wrote:I was hoping someone could tell me if Windows manages memory in a similar manner.
No, AFAIK Windows doesn't, at least not exactly. Using Windows you'll always have plenty of free memory, which surely seems a waste.
On Linux it's very similar to OSX, all free memory is used up as cache, and can be given back at any time.
But I think you're misunderstanding what this feature is actually doing. I'll try to elaborate:
First there is the distinction between virtual memory and physical memory. Each application has 4 GB of virtual memory space (on a 32 bit system, more on a 64 bit system). The application can request as much of that virtual memory as it wants, up to the 4 GB limit (actually 3 GB, because the operating system needs a bit of it). It doesn't really matter how much the application requests, as this is just virtual memory.
There are several uses for virtual memory:
- The application just needs some anonymous memory. When it requests the memory, nothing actually happens. On first use, physical memory is allocated. This memory stays allocated until the application explicitly frees it. This is the memory that actually matters.
- The application needs a file (e.g. a library): The file is mapped in the virtual memory. When it is first accessed, physical memory is allocated and a part of the file is read into it. This memory has the property that it can be freed at any time, at the cost of some performance because the file has to be read again on next use. This physical memory can also be shared between multiple processes that need the same file. This is especially important because there are many libraries in the system that are needed by most programs.
(there are a few more, but these are the most important ones)
Now let's get to the physical memory. Applications never use physical memory directly, it is managed by the operating system. The operating system can basically do the following with physical memory:
- Satisfy the virtual memory needs of applications.
- Use it as backing store for mapped files.
- Cache data from other file system operations.
What is really interesting for the performance of a system is of course the physical memory. Virtual memory basically never runs out (at least with 64 bit systems).
What happens now when physical memory runs out? The operating system has several possibilities:
- Swap some anonymous memory.
- Throw away the memory of a mapped file. It may be necessary to write changes to disk first.
- Reduce the file system cache size.
There is actually no way for the operating system to just "throw away" some memory of an application, it always has to be swapped. But it can throw away the backing store of a mapped file, since it can just re-load it from disk at any time. And of course it can do with the file system cache whatever it wants.
What will the operating system actually do? It depends on the situation. One might think that swapping is always worse as long as you can reduce the cache size, but that's not necessarily true. If memory is used relatively infrequent, swapping might well be the better choice.
The article you linked above does talk about total memory consumption, and why it is always near 100%. That's simply because the operating system is always filling it up with the file system cache, and that's nothing to worry about.
Memory consumption of single processes is a different matter. Here you basically have two numbers: Allocated memory, and committed memory (sometimes incorrectly called virtual and physical). Allocated memory is irrelevant, since that's just memory that the application requested but did not actually used. Committed memory on the other hand is memory the application actually uses, and the operating system can't do anything about it without sacrificing some performance. The only memory the operating system can just throw away without affecting anyone is the cache, but you will never see the cache counted towards the memory consumption of a process.
So if an application uses 300 MB memory according to the task manager, it actually needs it. It may be that some of this memory is only used infrequently, and there is not much harm in swapping it, but it still means the application needs the memory, at least as far as the operating system is concerned.
This explanation applies exactly to Linux and OSX (and probably every other Unix out there). It also mostly applies to Windows. It works slight different, but the conclusions are still the same.