Since I upgraded to Mac OS X Lion I’ve seen what I consider an abnormal rise in the App Store of micro utilities to recover memory.
Judging from some screenshots those small applications resides in the upper tray and if clicked will present a button that when pressed it start some procedure to gain back memory and make it available again for the operating system to use.
My late 2008 MacBook Pro has “only” 4GB of RAM and is suffering a lot in the memory department.
While it’s true that developing scalable web applications should not consume too many resources, all the hope is lost when you call your army of Virtual Machines to do your bidding.
I went for a fresh Lion setup and installed only a handful of applications specifically ready for Lion along with all the available updates.
Compared with the previous Snow Leopard setup, now happily living in an external disk thanks to SuperDuper!, Lion feels slow, and clearly, just by looking at the Activity Monitor, one of the bottlenecks here is the RAM.
I’m currently waiting for my 8GB upgrade and see if the situation improves (if it will work of course).
The reason for this post is that I noticed that every major app on my fresh install is taking up to 200MB+ or more, without even including the hungry and infamous the-more-I-have-the-more-I-want kernel_task, which does seem to raise a lot of confusion on official Apple forums.
I’ll illustrate in Lion how to achieve the same benefits that those applications provide, in a set-and-forget mode without spending a dime.
Using the technique below I noticed significant gains, you can verify them aswell by opening the Activity Monitor.app, right clicking the icon in the Dock and setting it to show the Memory.
Keep an eye on the green part of the pie chart when the script runs.
First, select the text editor of your choice, I personally use Textmate, and create a new file:
mate ~/Library/LaunchAgents/org.icoretech.purge.plist
For the bash novices the tilde (~) sign indicates your home directory, usually /Users/yourname
Copy/paste this code:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.icoretech.purge</string> <key>Program</key> <string>/usr/bin/purge</string> <key>StartInterval</key> <integer>3600</integer> </dict> </plist>
Save the file (CMD+S will suffice) and close the editor.
What we just did is to build a plist file that instructs our system to run the value of the Program key (/usr/bin/purge) every 3600 seconds.
Open up a Terminal and write this:
launchctl load -w ~/Library/LaunchAgents/org.icoretech.purge.plist
Now, this job will run every hour, you can tweak the number of seconds by changing the StartInterval integer number (in seconds) and it will free up your memory, you said it, for free.
To stop it:
launchctl unload -w ~/Library/LaunchAgents/org.icoretech.purge.plist
A downside of this is that the purge command will kinda freeze your mac for few seconds when it runs. It can be annoying at times.
$1.99 domains with SSL purchase!