Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'New Memory Wipe Command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
New Memory Wipe Command
Authored by: desepticon on Apr 11, '12 06:12:37PM

Okay I've done I bit of searching and I've come up with this:

About 1/3rd of the way down, user "theshadow27" has posted a link to a C++ program with an XCodeProject file and a ruby script that appears to call malloc to clear the inactive memory. I've compiled the program successfully in Xcode and it seems to work as described. I've only done some preliminary tests but this program/script combo could be used instead of the purge command to accomplish the task more effectivley.

He also had this to say about the whole "Inactive Memory" Issue:

"From my informal tests, the system is more responsive when running with "Free Memory" than "Inactive Memory." As a computer scientist and electrical engineer to me the reason for this is fairly straight forward. When the Kernel has free memory to work with, it can allocate it without thinking. When it's inactive memory, no matter how fast/efficient/wonderful the MMS is, it still has to page out that data. What "clearing the inactive ram" means to me is:
--Forcing the Apple MMS to preemptively page inactive memory to disk so it is not done at the time of allocation.--"

Can anyone take a look a this program and tell me a little more about what it's doing and if its a step in a better direction. Is there any way this can be altered to better suit our purpose?

[ Reply to This | # ]
New Memory Wipe Command
Authored by: arcticmac on Apr 11, '12 09:06:59PM

It's certainly true that it adds complication to the system to have to clear inactive memory before it can allocate more, but it doesn't account for much time, and it turns out that what was in that memory was often useful.

The way his program works (which is essentially the same as the one I linked to in my comment above) is to allocate all of your free ram, thus (assuming things are working properly) forcing the kernel to flush the disk cache, which is essentially the same operation that purge performs, though it wouldn't surprise me if 'purge' does it in a more efficient way.

As a little experiment, open a terminal and run 'time purge'. Then run it again. Notice that it doesn't take dramatically less time to run the second time than the first. Now try switching back to your web browser. Notice how it takes a bit longer than usual the first time for the window to become "active" again? Try launching a new app (e.g. I did 'open -a "Activity Monitor"' in the terminal). Notice how long it takes. Quit it and launch it again. Unless it's a much bigger app than Activity Monitor, it appears almost instantly. I think it's pretty clear that the disk cache does serve some definite value, and that clearing it too often is probably not a good idea.

On the other hand, I'll also grant that the system doesn't work perfectly. There are certainly times when I'm sitting there on top of 3/4 of a GB or more of cache/inactive memory and my system gets busy swapping away some memory or other to disk to make room for the latest thing. Which is _not_ good for performance either. Sometimes it might be worthwhile to 'purge' in a situation like that, but really it depends. Often as not, I find that quitting Safari or Xcode or Matlab or any of my other big memory-hogs is a bigger help.

What I'm trying to say is that there might be situations in which 'purge' can help, but that you shouldn't just assume that it actually makes things faster just because the 'free' RAM went up; and I definitely wouldn't advocate running it automatically repeatedly unless you have solid evidence that it increases system performance for the particular task at hand.

[ Reply to This | # ]
New Memory Wipe Command
Authored by: desepticon on Apr 11, '12 10:34:24PM

Thanks for the info. It seems to me that this guys program does something a little different from purge though. It causes no noticeable lag on my system when run. When I run purge it takes a few seconds and the system hangs. I'm not sure this program is affecting the disk cache at all. It doesn't seem to be as vicious about reclaiming memory.

Like you say I think this practice can be used in certain situations. In my case I run a Plex media server. This program has the habit of claiming more and more RAM over time and being stingy about releasing it back to the system. The computer I run this server on also multi-purposes as a MediaMac, Game System, WebServer,rtorrent setup, and generic purpose computing hub. In some instances, especially when I want to play a game, it seems to be best to start with as fresh a canvas as possible as far as inactive memory is concerned. I don't know when I might feel like playing a game, so a script such as this running automatically would allow me to "set it and forget it."

Hmmm. Thinking about this now wouldn't it be possible to attach a lauchctl watchpaths directive for certain applications you want maximum memory performance from? Does watchpaths support multiple paths?

[ Reply to This | # ]