Home / Using purge to free inactive memory on Mac OS X

Using purge to free inactive memory on Mac OS X

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 without having to reboot.

The purge command comes with the developer tools so you need these installed in order to use the command.

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.

Update March 18th 2011

Thanks to one of my readers for helping me work out that you need to have the developer tools installed in order to have the purge command available.

I’ve also moved to using a MacBook Pro since writing this article which has 8GB of RAM (compared with 4GB on the MacMini) and so I personally no longer have issues with free memory.

Update January 19th 2012

Recently I’ve found the purge tool no longer works (at least not for me), getting the following errors:

[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPAddressSpace.c:608>	Unable to open user client for address space 13583, error 0xe00002bd.
[ERROR]	<CPDevice.c:4013>	Unable to get all available address spaces.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:4252>	Unable to update device instances (including replacements) for "osx:Mac OS X 10.6" (0x103357740), error kCPUnknownError.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPDevice.c:3752>	Unable to create new counter client.
[ERROR]	<CPOSX.c:1172>	Unable to get user client so as to poke the kernel.
Unable to purge disk buffers, error #-2.

I’ve found a free app from the app store which seems to do the trick. Read about it in my "free inactive memory on Mac with FreeMemory" post.