Quick Tip: Regaining Stolen but Unused Memory

Joined
Apr 6, 2011
Messages
1,291
Reaction score
43
Points
48
Location
Louisville, KY - USA
Your Mac's Specs
MBP 17" 2011, 2.3GHz Intel Quad-Core i7, 8GB RAM, MacMini 2011, 2.7GHz Intel Dual-Core i7, 8GB RAM
Saw the tip on TAUW yesterday about opening up Terminal and typing PURGE to clear out memory that was being hogged by applications, but not actually being used by applications. Worked well, and when I gave it a shot, I regained over 3GB worth just from closing Aperture itself.

This was great, and the tip worked well, but you have to watch the Terminal window to know when the command was finished. And if you are not one who is comfortable with Terminal, then the command would be useless. I went ahead and, by using Automater, created an APP for that. ;P

* Open up Automater and on the left column, choose "Utilities".
* Then, you will want to choose "Run Shell Script" next. Double-click on it to open the box on the right where you can type in the commands.
* Use /bin/bash for the Shell.
* In the drop-down near the right top, "Pass Input: to stdin."
* Here is what I put in, the 2nd line is for me to know when to command is completed. The Mac will actually speak the line, not pop up a dialog box. And, I like campy things sometimes.

purge
say "Memory Purge Complete."


* Before saving, hit the Run button in the top right to test. If all goes well, you should hear the computer speak "Memory purge is complete."
* Next, hit the menu File -> Save
* I choose to save the application into my Application folder rather than the default "Documents"
* Now, you can run it at any time without worrying about the Terminal window or waiting.

Check the screenshot below. It shows my screen with it programmed.

image.jpg
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
It's important to note that the purge tool will clear up your inactive memory which may not be all that helpful. To better explain this, one needs to know what inactive memory is. Inactive memory is memory that was used by various applications. When you close an application, the memory it was using is relabeled inactive. The purpose of this is quite simple - when you attempt to reopen an application, the inactive memory for that application becomes active again. This process of "relabeling" the memory is much quicker than reallocating it and as a consequence, your application opens faster (ever notice that an application always launches faster the second time?). What's important to note though about this memory is that it can, if need be, be reallocated if you run out of free memory. In effect, it lies dormant until it's needed by either the application it was allocated to or another if you run out of free memory. Perhaps an example will make this clear.

Let's say that you have 1GB of memory and you open an application that needs 500MB. Upon launching that application, you now have 500MB of active memory and 500MB of free memory (I realize that I excluded wired but that complicates the example). You use the application for a while and then quit it. You now have 500MB of free memory and 500MB of inactive memory. If you were to relaunch that application, the 500MB of inactive memory would be "relabeled" active memory. However, let's say you launch a second application instead of the first and it needs 700MB of memory. In this case, it would appear that you don't have enough free memory. Remember though that inactive memory can be reallocated so 200MB of that inactive memory will be reallocated automatically by the OS.

I say all of this because the purge tool, while clearing out the inactive memory, is largely unneeded for most users. If your machine needs some of that inactive memory, it will just take it.
 
OP
Deckyon
Joined
Apr 6, 2011
Messages
1,291
Reaction score
43
Points
48
Location
Louisville, KY - USA
Your Mac's Specs
MBP 17" 2011, 2.3GHz Intel Quad-Core i7, 8GB RAM, MacMini 2011, 2.7GHz Intel Dual-Core i7, 8GB RAM
I was being lazy, truthfully. I didn't want to open Terminal, just to type Purge. I have created it on my MBP, but copied it to my Mini as well. Now, I just hit the app from the dock and all is done.

I use a ton of scripts in the Windows world to do daily redundant tasks. I am now working to do the same on the Mac side as well.
 
Joined
Sep 5, 2012
Messages
4
Reaction score
0
Points
1
How do I know how much RAM was purged? (Excuse my ignorance, I am new at using automator).
 
Joined
Sep 30, 2007
Messages
9,962
Reaction score
1,235
Points
113
Location
The Republic of Neptune
Your Mac's Specs
2019 iMac 27"; 2020 M1 MacBook Air; macOS up-to-date... always.
Vansmith is spot on. Routinely purging the RAM is a placebo to treat a non-existent problem and is even counterproductive. If you have an app that is acting up and eating up RAM when it shouldn't be, then purge may need to be run, but then it'd be more prudent to find the culprit and handle it from there. This is like trying to kill a cockroach with a grenade.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top