Update 2020
This question was asked in 2012 and this answer was written in 2020, and some things have changed in the interim, but a lot has remained the same.
I believe most of this question, the answer from Quantumpanda, and the description from Apple Support article suffer from a misunderstanding of the nature of "inactive memory". The OP points to Apple Documentation that says
In OS X, when the number of pages in the free list dips below a computed threshold, the kernel reclaims physical pages for the free list by swapping inactive pages out of memory.
The Apple documentation said that in 2012 and still says that in 2020. However, that quote comes from the "Paging Out Process" section of the documentation; the OP missed the discussion of "Page Lists in the Kernel". The key sentence (for our current purposes) in that section is
If an inactive page has not been modified and is not permanently resident (wired), it is stolen (any current virtual mappings to it are destroyed) and added to the free list.
What the Support Article was talking about
For example, if you've been using Mail and then quit it, the RAM that Mail was using is marked as Inactive memory. Inactive memory is available for use by another application, just like Free memory. However, if you open Mail before its Inactive memory is used by a different application, Mail will open quicker because its Inactive memory is converted to Active memory, instead of loading it from the slower drive.
In order to run a program, Mail in this example, the code for that program is read from disk and written to RAM, because the CPU can only execute code from RAM. The OS keeps track of the fact that the RAM is a copy of a file on disk, and it keeps track of whether or not that data in RAM has been modified. When the Mail program exits, the RAM copy of the file is no longer needed and ends up on the "inactive" list. However, if there is plenty of RAM to go around, there is no need to destroy the data in the RAM, so it is just left as-is.
Now if you run the program again right away, the OS does not have to copy the code from disk to RAM because it can see, by looking through the inactive list, that it already has a copy of the file in RAM, so it just moves that RAM to the active list and assigns it to the new running Mail program. This is much faster than re-reading the file from disk.
Mail is a bad example, though, because you are not often stopping and starting the mail program. However, there are dozens of small programs the OS runs in the background, such as to keep Spotlight indexes updated or keep your local data in sync with iCloud, that are frequently run and then quit when done. For these programs the time savings is much more significant.
The critical point: this kind of inactive memory is never swapped
This kind of memory, which is backed by a file on disk and not modified, is never written to swap, because there is already a copy of it on disk elsewhere. This is the kind of memory called out in the added quote above: "has not been modified and is not permanently resident". When there is not enough memory, this kind of inactive memory is not swapped, it is stolen and placed directly on the free list.
Inactive memory that is swapped is memory a running application still needs
The other way memory become inactive is if an application has not touched (read from or written to) it in a while. For example, if you are working in a word processor and have several open files, this might be information about one of the files you have open but are not working on. When memory runs low, this kind of memory is swapped out to disk to make room for whatever is requesting memory it needs right now that is causing memory to run low.
This kind of inactive memory must be swapped out because it contains data that is not saved anywhere else. The only way to prevent this kind of memory from being swapped out is to disable swap entirely, and that is almost always a poor choice. When you disable swap entirely, you reduce the capacity of the system significantly. If you limited the system to only running what it could run with swap disabled, it would perform just as well with swap enabled.
purge
is a red herring
The purge
program is a counter-productive red herring. It will force the inactive memory that would be stolen rather than swapped to be stolen right away. That may look good for the numbers, but it actually hurts performance in 2 ways:
- It takes time to run the
purge
program
- It removes the performance that is gained by keeping track of what the inactive memory contains and allowing it to be reused.
Bottom line: do not try to disable inactive memory swapping