RAM usage explanation from a Unix guy
Every 2 months or so, somebody wonders aloud why OS X seems to require huge amounts of RAM to do nothing.

This is a perfectly reasonable question, especially if you used previous versions of the Mac OS. After all, in OS 9 and earlier, you
had to manage your memory carefully. There was only so much to go around, and you could actually instruct a program as to how much to use.
Keep in mind though, that OS 9 can trace its lineage directly back to the OS that shipped with the original Mac. We're talking early 1980's memory management technology here: The user. Back then, no home users had a gig of RAM and 20 apps running on their boxes simultaneously. There weren't 16 users logged in and doing all sorts of things at once.
Welcome to Unix, my friends.
Unix-like operating systems had to manage their memory, and do it well. Unix has been a multi-user OS from its humble beginnings in academia. 20 physics researchers logged in and running simulations? You
better have a good memory manager, lest researcher A's data accidently mingle with researcher B's ... who wants to sort that out ? Not the Unix sysadmin guy - he had better things to do, like play Nethack and Netrek.
Why is OS X Using All My RAM?
Good question. We'll get to that in a second. But an equally valid question that no one ever asks is: Why
isn't my operating system using all my RAM? You paid good money for it, didn't you? Wouldn't you
want to get your money's worth? What good is RAM if it sits there doing nothing? The point of memory is to store information. If it's not storing anything, then there really isn't much point to having that RAM.
Here's where OS X (and other Unix / Unix-like OSes) differ from what many Mac users are used to:
The philosophy behind memory management in OS X is that unused memory is
wasted memory. Accessing the disk is slow. On a multi-user system, if things get slow, users complain and we sysadmins get very, very unhappy. So, OS X is designed to keep information "handy" in RAM. People are creatures of habit - we tend to do the same tasks over and over.
So, if you've been browsing the net and then close Safari, there's still a pretty good chance that you'll open it up again. Why free up all the RAM that Safari was using the instant you close it, if you're going to turn around and re-open it five minutes later?
Instead, OS X keeps some of that data laying around in RAM for when you next open Safari. But, it marks the memory as
inactive. When you next try to open Safari, there's less to load in from disk because OS X can access data from the Inactive memory pool. Therefore, Safari loads faster and people are happy.
But wait! What if I never open Safari again? Or what if I open a really huge honkin' Photoshop file and need that memory back? Is there any way to get it back?
You're in luck. OS X does this for you automatically too! Notice earlier I said that RAM that stored information that was no longer in use was marked
inactive. RAM that contains nothing at all is called "free" memory. OS X always tries to keep a certain amount of free memory. If you suddenly open a huge document that eats up a bunch of your free memory, OS X will
automatically empty some of your inactive RAM and turn it into free memory, making it available for new programs to use.
OK, so I get it. Inactive RAM is like a buffer - OS X keeps data around in inactive RAM in case I use it again. But if I don't, OS X will free up the inactive RAM and allocate it to new programs automatically.
So, that about covers it. The next time you notice that you've only got 7 megs of free memory left in Activity Monitor (or top from the Terminal), check to see just how much memory is Inactive. You've probably got more than enough for your needs. OS X is just doing its best to make your user experience a fast and pleasant one.
Like I said: You paid for the RAM? Why
wouldn't you want to use it all?
Hope that helps.
(note: the above is a simplistic view of what's going on, but accurate enough for most purposes. Any BSD or mach kernel hackers that might be reading this, sorry if I've glossed over any of the details.
