Free Up Inactive Memory in Mac OS X with Purge Command

Mac OS X has fairly good memory management but it’s not perfect, and sometimes RAM can be held unnecessarily in the “inactive” state despite the contents no longer being needed. If you’ve been participating in memory heavy activities or you just need to free up some available RAM you can actually force Mac OS X to clear out inactive memory.

Launch Terminal, found in /Applications/Utilities/ and enter the following command

sudo purge

Give OS X a minute or two to complete the process

Note: some versions of OS X may not require you to prefix the purge command with sudo, while running with sudo will require authentication, like so:

sudo purge

Open Activity Monitor to see the before and after results yourself, you’ll find dramatic changes at the “Free”, “Used”, and “Inactive” meters under System Memory.

The purge command forces disk and memory caches to be emptied, offering a ‘cold disk buffer cache’ which is similar to the state of the operating system after a reboot. Of course, the benefit of using purge rather than rebooting is that you don’t have to restart the machine and you can maintain currently active applications while still freeing up memory.

This is not necessary for most Mac users, but power users and those with heavy memory demands will undoubtedly find this command helpful in the future. If you feel like you are frequently hitting a memory ceiling learn how to check if your Mac needs a RAM upgrade and consider upgrading, it can dramatically improve overall system performance.

Note: You may need to have XCode & Developer Tools installed in order to use the purge command, that can be downloaded for free from the Mac App Store.

Related

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

69 Comments

What a bad a piece of advice. Inactive memory is exactly the same as free memory only that it was recently used and might help launch/use apps quicker. Transforming inactive into free memory will always make things worse and slower.

In theory you are correct, but OS X is notoriously flakey with memory management. The purge command may make existing applications slower that had old data stored in memory because it has to load the data again, but it will speed up anything fresh considerably because it doesn’t have to make room in the buffer.

It’s no harm to run, though don’t expect any performance miracles. If you need more RAM you simply need more RAM and it’s time to upgrade.

Perhaps it’s anecdotal, but once “Free” memory is used up OS X starts using swap immediately which results in considerable system slow downs. This is probably a result of how certain applications manage memory more so than the core OS, but selectively using purge can avoid swapping in many situations. It certainly isn’t magic and you’re right it’s best used by individuals who know what they’re doing. It would only slow down relaunching applications or reloading data that was previously stored in memory, but it won’t impact system performance elsewhere.

Actually, this is not a bad piece of advice, TYVM. I really appreciate the purge command. This inactive memory thing has been annoying me for a long time now.

Here’s what typically happens to me, and how the purge command helps. When I’m working, I use lots of different programs one right after another. I don’t necessarily use them all at the same time, so its not that I’m running out of memory due to multitasking. For example, I open up Illustrator, edit an EPS file, copy it to the clipboard, close Illustrator, and then dump it into Photoshop to rasterize it at a specific resolution. I do some work on it, then open up a few tabs of Chrome to research some GFX techniques. I close Photoshop and then open up a terminal and boot up a Ruby server to test out the new file on my web app. I need to edit some code, so I open up Vim and split it open in a few windows while making some notes and screenshots of what I did in a Word document. But, to my horror, everything starts slowing down drastically. I notice that I have 1.5 GB of my 4 GB sitting in Inactive memory. In this scenario, I don’t have to buy more RAM – its getting mismanaged by the OS. It still thinks I need that RAM that I used earlier in Illustrator and Photoshop. But I don’t need that RAM. I’m not going to use Adobe for the rest of the day. I need the RAM to be freed up for Chrome and Ruby. So, the problem is a mismanagement due to the OS. Granted, I could buy more RAM, and it would mitigate the issue, but it doesn’t truly solve the problem. I shouldn’t be forced to buy memory when it really isn’t the root of the problem.

So, I’m grateful for the purge command – it really allows me to keep my computer running for longer without having to reboot. :-)

@Aaron and @WebDude below, both of you mentioned Chrome. If, like me, you use Chrome for a quick Google search while running very heavy applications(I use Logic Pro, the GIMP/UFRaw, and Inkscape) then you should know that Chrome is rather heavy on the RAM. It can easily bring a computer to its knees. i’d recommend you check out OmniWeb, which is what I’m using at the moment. There’s a huge improvement.

It’s no substitute for Chrome but it won’t pressurize your RAM for some quick browsing.

It’s not the OS that’s the problem with memory management mate – it’s the applications that WEREN’T written by Apple that just “reserve” memory for no good reason (at least the apps I use – I’m a Linux/Mac guy so I’m in Terminal looking at things at the Unix level frequently).

Mac clearly has memory problems. If you kill all user applications, the sum of Inactive and Free memory should be nearly the same as a reboot. It is under Linux. I have been using Mac (and Linux) for years. If you start and stop the same group of large programs over and over you will run out of memory on a Mac. Purge helps. No need for purge on Linux. You can start and stop and programs on Linux till the earth stands still and it remains solid.

hey Pedro. That command works perfectly fine on my mac. I have a good piece of advice: don’t use purge command.
“unless you really, really know what….”
yeah I know, it’s nothing of a rocket science. Even you can grasp that.

“Inactive memory is exactly the same as free memory only that it was recently used and might help launch/use apps quicker.”

This is incorrect. It will help launch apps that were IN memory, or used a resources that was in memory quicker, but when you are launching a new app into a system where memory is fragmented into a bunch of cached chunks, the system struggles to get it the memory it needs, resulting in extremely slow app launches (and they don’t get any better, either, because all memory is still in use or fragmented.) Whereas if you use purge, then you can launch all manner of things quickly and easily because allocating memory for them is now trivial, it comes from a much more contiguous pool.

For instance, I have 8 gigs on this particular machine. Memory can get to a state where the free memory is a tiny green slice just a few degrees wide on the Activity Monitor pie chart. Start Lightroom in that condition, startup takes as much as a minute. Purge, system memory goes back to more than 4 GB free, and Lightroom starts in just a few seconds.

Things aren’t as simple as they might appear with regard to caching and memory management; there’s a limit to how much coalescing an OS can do in a live performance situation, because it is very resource-intensive. When you use purge, you’re essentially saying “right now, it’s ok to use all the resources you need to do the best job possible to free up anything that isn’t actually in use, and coalesce it into the largest free chunks possible.”

Finally, with SSDs available, caching drive data isn’t the boon it once was for many operations.

@Pedro – I wish that was true but it’s simply not. I regularly have 1GB-3GB sitting as “Inactive” and constantly run out of memory running Chrome and Photoshop concurrently. Maybe it’s those two applications fault, but I often get the Force Quit menu popping up telling me Mac OS X is out of memory and that I need to kill applications to free some up! I bet any motion designer, web developer, or graphic designer encounters this problem. I am running OS X Snow Leopard but my coworkers have similar issues with OSX Lion. I will try this “Purge” to see if it helps, thank you for the resource.

Oh really? I had no idea.
Did the purge command solved it?
Running out of memory is particularly odd because I thought the OS
would channel information to the HD whenever the RAM is fulll (isn`t that what Virtual Memory is all about?).

@Web Dude & @Pedro- If you are using memory intensive apps such as Photoshop, Illustrator, or any other Adobe Creative Suite Software or any Higher-End Graphical games such as Call of Duty: Black Ops you will simply need to upgrade your memory. I have a MacBook Pro (Early 2011-15.4″ 2.2GHz Quad Core i7). You can upgrade to 8GB DDR3 Memory or even 16GB DDR3 Memory if your computer supports it. Apple claims the MBP can only support 8GB of Memory but I am running 16GB 1333MHz of 204-Pin SODIMM Memory which only set me back $110, and comes with a FREE 8GB Flash Drive. Here is the link if you want to check it out: http://www.newegg.com/Product/Product.aspx?Item=N82E16820233217
This is the only memory people have not had problems addressing all 16GB of Memory and its manufactured by Corsair. Hope this helps you out!

@John – Actually, no matter how much memory you have you will run into this issue sooner or later. It’s just a matter of time. The bad memory management in Mac OS X has numerous times left me with all of my 16 GB ‘non-free’ and with page file usage growing until I’m out of disk space on my boot drive.

The solution: Run ‘purge’ and suddenly i have 8 GB ‘free’ and all of the page file space is reclaimed (though it takes a little time). So this is not a problem with insufficient memory… it will happen no matter how much memory you have (it even happens on my Mac Pro with 24 GB RAM).

Lion definitely still has memory management issues. I’ve used the purge command for about 6 months now and it keeps me from having to restart my Mac. Safari was awful until it was updated to better manage it’s memory usage in Lion. I’m on a 2011 Mini with 16gb of Ram and it still has memory problems, sometimes I’ll have 11gb of inactive Ram, under 1gb of free Ram, and things get slow. Purge frees up the Ram and things go back to full speed. Playing videos with a ton of inactive Ram results in stuttering. This shouldn’t be an issue with a modern OS, and definitely not with 16gb of Ram. Still, Lion is a fantastic OS, I just hope Apple gets the memory issues sorted out.

I can’t believe osxdaily is perpetrating this utterly misleading advice. Thinking that you have more “FREE” memory after purging is inaccurate!!! This memory optimisation hoax is the same misleading rubbish that plagued Windows for years.

Several of the commenters like Thomas and Will are simply incorrect to state purging disk cache won’t affect performance, it will!!!

I’ve watched a naive user using iFreeMem and mentally overriding the slowdown they get (they just junked their disk cache!) by seeing all the green in the pie chart — placebo against the evidence! Please correct this article.

Yes, yes, and yes, but I happen to have an application that changes its behavior when it sees free memory dropping below 1Gb, even though several gigs may be inactive. Yes, that application should change its behavior (it’s actually responsible for loading the huge amounts of data that are occupying the inactive memory), but it probably won’t, so I purge memory from time to time, and the app is happy.

There’s theory and then there’s reality. In reality, purge is very useful when you have less than 1% of free memory. I have 8GB of memory (max for my computer) and some apps eat it all up (XCode is one of them). Then my computer slows to a crawl. Purge frees up enough to get it working again. Sometimes I’ll follow this up with closing all the apps I’m running and doing a second purge. This frees up 4GB of memory for me on Mountain Lion.

What I would really like to see is a utility that limits how much RAM an app can allocate so I can put them in a memory sand box. Then I could make XCode (and other apps) behave themselves. Anyone know how I could do this???

For a critique of this memory “optimisation” for linux (which also assigns disk cache to inactive RAM, but can be reclaimed INSTANTLY as OS X does):

“Disk caching makes the system much faster! There are no downsides, except for confusing newbies. It does not take memory away from applications in any way, ever! … But what do you call memory that is both used for something and available for applications? You would call that “free”, but Linux calls it “used”.”

A great command, thanks for sharing this reference. You are correct, the memory management is a bit flakey, and I can easily go from 2.6gb of free RAM to about 200mb and into swap. I use to have to reboot my machine each time just to free it up and get some higher performance out of my macbook pro. This purge command is exactly the solution I needed!

Using the ‘purge’ command when Free memory starts to run low prevents the OS from having to use swap by converting (most) inactive memory to free memory. In my experience keeping my Mac from swapping to the disk (and causing Page-Outs) is key to maintaining optimal performance. To all the naysayers preaching about how wrong this advice is, you obviously haven’t run into the problem the rest of us are having.

I notice a significant slowdown on my Mac when free memory goes below 100MB. When this happens Activity Monitor shows “Swap Used” starts to rise above 0MB, and you can see Page outs starting to occur. This becomes a big performance problem, and I found myself having to reboot to free up memory to prevent the Mac from swapping to disk. This is a big PITA. I usually notice Activity Monitor reports there is about 1.5GB – 2.0GB (or more) of Inactive RAM. Using purge fixes the problem for awhile until the free memory runs out again.

I use my Mac Book Pro for work, and I usually find myself running purge once in the morning, and maybe 1 or 2 more times throughout the day to prevent disk swapping. I do find it disappointing that Mac OSX isn’t managing this for me, but whatever. I wish the OS would force Inactive Memory to be freed before using swap space.

Anyone who tries to tell me that running purge is a placebo is just plain wrong. My Mac is an Early 2011 Mac Book Pro, 2.3GHz i7, 8GB RAM running OSX 10.7.3. I run a Win7 VM using Parallels Desktop 7, giving 2GB to the VM.

I’m in the same boat as everyone. been using the purge command and it definitely helped. I even testing out just leaving my Imac with 12 gigs memory overnight and only think that run in the background is firefox, safari and chrome. In the morning, of course, i have less than half a gig of free memory without doing anything.

I have to use purge command to prevent from reboot. Latest Lions OSX.

I think I’m giving up on this issue bcz apple supports have no clue what’s going on.

Thank you! I had nearly 8GB of 16GB Inactive memory for the past several days hours. Sometimes it will free up overnight as the system realizes it is not actively being used. Many times it sits used (Inactive). Running memory hungry applications does not force it to be freed from inactive programs, and the experience very obvious slowness due to lack of Free memory.

Regardless of what you call it; hoax, misguided, unnecessary, the Purge command does the trick.
I now have 6Gigs of Free memory useful for the applications that need it.

Thank you again, I no longer have to reboot merely to clean up memory!

Great command, as a web developer I use memory intensive applications all the time. More specifically however I often download large sql backups of our live databases and restore them locally on my machine. This makes my life easier as I can modify code whilst still using a fairly up to date set of data and without having to rely on an internet connection or latency on connecting to a remote database. I have found that restoring the database on the command line (postgres) gradually eats up my memory and when the restoration has completed sits as inactive memory (up to 5 GB of 8 available). This inactive memory fails to clear (or at least takes hours upon hours). I know I wont need to run this restore command that often so using the purge command prevents me from having to reboot. Thanks for the heads up.

This was a very helpful discussion. I am a power user of LR4 and PS6 and I noticed a SIGNIFICANT system slowdown when I had exhausted my FREE memory. After I upgraded my MacBook Pro to 8GB, the max, this happened less often. Frequently, I have LR4, PS6 and other applications running concurrently and the OS manages it fine. However, sometime I only have one power app like PS6 or LR4 running and I still run out of FREE memory, with the same result. Quitting and restarting the apps only frees up a small fraction of my 8GB and this is quickly reallocated and the problem comes back. It was only by restarting my computer that fixed the problem. The “purge” command saves me the trouble of restarting and valuable time.

Related to all this, does anyone know what cont_datapost processes are? They look like little 80-100 Mb memory leaks, and they accumulate over time. Purge will not make them go away. You can see them on Activity Monitor. I ran a backup to my NAS, and after a few hours, there were about 30 of them, and my free memory was nearly gone; I was not running anything else at the time.

I have a Mac Mini (i7 on 10.8), which I use as a Media Server. Currently, I have 16GB of RAM installed, and I’ll sometimes end up with about 11GB in “Inactive Memory” when looking at Activity Monitor. I typically restart my machine about once per week, but I tried this Purge command in Terminal today, and the Inactive Memory immediately went back in to “Free Memory”. While I don’t know why so much RAM goes into Inactive (I usually only have iTunes and Plex Media Server running–which is set to scan manually) I am glad that there is a command for when I am in the middle of a process and need to purge. When I am in a situation where I am able to shut my computer down, I will, since I tend to only like to use workarounds/shortcuts in critical circumstances, not as a go-to. I am hoping there are no long-term effects caused by reallocating memory in such a brash way. So far I’ve read a lot of debate in the comments thread, but no one has made enough of an intelligent argument to convince me either way.

purge command is a lifesaver. I could not function without it. When Free memory goes below 100MB my macbook pro becomes unusable. I have to run it several times a day, which really is a mark of bad design in iOS memory management (my opinion only).

Make sure you have Xcode installed as well as the command-line tools installed. You can find this by opening Xcode, selecting Xcode from the Menu Bar and clicking Preferences. When the preferences menu comes up select the Downloads tab and make sure you are looking at the Components section. You should see a few iOS simulators and Command-line tools. It will either have a button to install it (~150 MB download) or it will say Installed.

To explain this a little further, purge simply removes all the inactive RAM, or RAM that is not in use, as well as some of the unnecessary active RAM, RAM used up by a program that has not been labeled as inactive (e.g. the previously played song in iTunes, or Pages/Word after you close the application).

The OS has 4 states of RAM, Wired, Active, Inactive, and Free. Wired is what is being used by the OS (e.g. Kernel task), Active is memory used by User and non-essential System applications, Inactive is memory that just hangs there in case you need it for future use, and Free memory is memory that has not been used, or Inactive memory that has been released from the RAM.

Purge isn’t always the best answer for everything though, sometimes you want that cache on the disk for storing information for later use (e.g. downloading a game from the Mac App Store that is larger than your total RAM). Inactive memory *should* automatically cache but when doing a single operation like this it usually starts caching when the RAM gets to about 100 MB or less. It then starts caching to disk and using purge could corrupt your download.

Purge should only be used when you want your system in a fresh state such as playing a RAM intensive game, or if you need to test for memory leaks in a program you are developing in Xcode. (the reason why you need Xcode) Running the purge command after your computer has been on for a while will cause it to run slow for a few minutes because it has to re-address RAM to the applications that are already in use.

I hope this helps, this is the short of the long of what I pulled from Apple’s developer pages on memory management in Obj-C and Cocoa.

This is exactly what I have been looking for!!! Using Adobe Illustrator with huge files, the MAC’s system memory isn’t purged after the file(s) are closed. This means that if you try to open another large Illustrator file you will get an “File is unopenable” error message. Before knowing this, I would have to quit Illustrator to clear up memory so I could continue working. Thanks so much!

Hi mates.
I have an iMac Intel 3,06GHz Dual Core Duo, 4 Gb Ram with 10.6.8 installed.
My problem is as follows: after I switch it on and run some common applications (iMail, Safari, iTunes) suddenly my available memory starts being eaten up and drops rapidly to around 100 MB or lower and everything starts running like a snail (so to speak). I have installed Onyx, but I cannot find the purge command (there is no memory tab). Any suggestions?
Thank you.

I have a background in operating systems…I can tell you that Mountain Lion suffers from memory mismanagement. Most programmers dont even understand virtual and physical memory, and leave memory leaks throughout their code. The OS should reclaim the pages it can, but the reality is different. Sometimes you have to provide a hint to the OS.

[…] using OneTab to generate the link list, follow it up with a quick usage of the (controversial) purge command, which should free up another 200-500mb of RAM in most cases as it dumps additional caches from […]

hi. thought i wud leave a comment on here as at the top ppl saying… good advice…bad advice etc. here is what happened to my macbook mid 2010 4gig ram. i installed parallels and windows 7. 30 meg of ram left. the system was unresponsive. the beachball thing to the point where i click safari and looked at the spinning ball and nothing for what felt like almost a minute…i searched and found this forum…typed purge and guess what…..800 meg free ram…safari worked as did other apps that previously wouldn’t open for ages. so i think the purge command makes the macbook work.. because before i typed purge…it was unusable. im now gonna search for programmes such as ifreemem and others so this happens automatically. until i decide what app to spend my hard earned money on. ill continue to type purge. cos it works for me. hope this helps some1 out thx. ps mountain lion. thx

For those wishing to automate the running of purge, open a terminal and enter this command: “sudo crontab -e”. it will ask you for your password. sudo is a command to allow you to run things as root. So the above command says to edit the root user’s crontab, which is a list of scheduled tasks. For most people, this will be empty initially. When you run this command, it will open up the crontab in an editor (probably vim. Google “VIM commands” if you don’t know how to use it). You need to insert a new line to run purge on a scheduled basis. Google crontab for details on how it works.

Add this line to the crontab you now have open:
0 */2 * * * /usr/sbin/purge

The 0 indicates the top of the hour (change to 30 if you wanted it to run at 30 minutes after the hour for example)
The */2 says run every 2 hours. You can change this to just * for every hour, or */6 for every 6 hours, or whatever.
The next * is day of the month (every)
The next * is month (every)
The next * is day of the week (every)
Again, google crontab for more details.

Save the crontab and exit. Now purge will run for you with whatever time frame you entered (in the example, every 2 hours, every day, at the top of the hour)