Using purge to free inactive memory on Mac OS X

By (author unknown), Chris Hope's LAMP BlogNovember 16, 2010 at 11:00PM

Apple Mac OS X is generally good at memory management but I sometimes find the inactive memory takes a long time to be released as free memory and my system can grind to a bit of a halt if I need to start up a virtual machine. This post shows how to use the purge command to free up the inactive memory.

Free, Wired, Active, Inactive, Used Memory

The screenshot below is from the Activity Monitor and shows the current free, wired, active, inactive and used memory.

memory usage in mac osx activity monitor

Briefly, free memory is available to be used right now; wired memory is basically system memory for the kernel and other stuff; active memory is memory being used right now; and inactive memory stores info from recently quit applications. The idea with inactive memory is that if you quit and app and start it up again it’s going to launch nice and quick because the info is still in RAM.

Inactive memory can be slow to free up

One of the issues I’ve often found is I want to fire up a virtual machine, which needs say 600MB or so, and I’ve only got 350MB or so available free but loads of inactive memory, as shown in the screenshot above.

I start the virtual machine up and then may as well go and have a lie down while I wait. The free memory quickly gets used up and then slowly, ever so slowly, memory gets freed up from inactive.

Sometimes all you need to do is quit a few apps and it sorts the issue out, but sometimes I’ve done this and I still don’t get much free memory made available, or I need to keep using the other memory consuming apps while I debug something in a web browser in a VM.

Using the purge command

There is a command called “purge” which can be used to free up memory. You should really use it sparingly (if at all) but it does actually free up all the inactive memory. Note that I’m not necessarily recommending you use this function but that is available should you want it.

Simply open up a terminal and run this:

purge

It may take a minute or so to free up the memory, and you may find things run a little slowly for a bit but sometimes if you really need that memory freed up right now it’s the only way I’ve found out to do it.

I’ve generally found it’s faster for me to use purge before firing up a VM if I don’t have enough free memory available than wait for the system to grind along while the VM boots up if a lot of RAM is inactive.