Finding source of leaking active memory on Mac OS Lion

0

Possible Duplicate:
Mac OS X: What is using my ‘active’ memory?

My activity monitor shows 6GB of active RAM usage:

Activity monitor screenshot

Yet my Real Memory column shows nothing like that amount:

enter image description here

(There's another screenful below that, all smaller.)

Backing that up, the output from this command (which sums up memory usage of every running process):

ps -axm -o "rss,comm" | awk 'BEGIN { s=0;}; {s=s+$1;}; END { printf("%.2f GB\n", (s/1024.0/1024));}'

Gives 4.09GB, so it looks to me like 2GB has leaked. I see much wider ranges sometimes, perhaps 2 or 3GB from the ps command and as much as 7 or 8GB of Active usage reported by Activity Monitor.

I've tried quitting everything and logging my user out and back in again, but the Active usage is still far higher than the RAM reported by ps and by each process to Activity Monitor. This 2GB of active RAM is basically unrecoverable unless I reboot. Is there any way to a) detect what's leaking and b) get it back?

Thanks

Tim

Posted 2012-11-29T17:02:08.440

Reputation: 297

Question was closed 2012-11-30T12:55:46.677

Is your system getting noticeably slower? I hate to ask, but: Do you want your RAM to be actually used or not? There's not really much point in having lots of RAM sitting around free, waiting to be used. (FWIW I do see less active memory being used for my MBP though – 3.64GB in contrast to 4.54GB as output from your ps command) – slhck – 2012-11-29T17:08:03.657

@slhck yes, it gets slower as it comes close to the stops. I should have added that I see this usage growing slowly, very much behaving like a leak. – Tim – 2012-11-29T19:29:30.140

@DavidSchwartz I read that question. My issue is slightly different, in that there's a clear disparity between active usage reported by the sum of the processes and that reported by the OS. – Tim – 2012-11-29T19:31:49.563

Sigh Not a duplicate; the linked question was answered by matching the active memory reported in activity monitor to that reported by the processes using the ps command I listed. In my case, there is a significant and increasing difference, indicative of a leak. – Tim – 2012-12-01T14:34:58.687

Answers

0

It hasn't leaked, it's just not worth the effort of making it free. Your system isn't memory-constrained, so having more free memory wouldn't provide any benefit. If the system makes it free, odds are it would either never get used (in which case making it free was wasted effort) or just get used again (in which case making it free was wasted effort).

Free memory is only needed in a very limited set of circumstances. And your system has more than enough free memory to handle those.

See this answer for a more detailed explanation of why you want as little free RAM as possible. Particularly this portion:

You must be thinking "I want free RAM so I can use it later". But now is later than it was before. And if you use it now, you can also use it later. All that happens if you don't use it now is that you forever lose the opportunity to use it now. Later never comes -- it's always now. Use the RAM now. Don't save it for later because then later you'll want to save it for later too.

It's not like [on a machine with 8GB] if you use 4GB now you can use 12GB later. If you use 7GB now, all that happens it that 1GB went to waste. You want as little free RAM as possible so your system can get the most benefit from the RAM you have. You can't save RAM. The opportunity to use that RAM now must be used now or it's forever lost.

Also, see this answer for more on the specifics of "active memory" on OSX.

David Schwartz

Posted 2012-11-29T17:02:08.440

Reputation: 58 310

David, The quoted section is a little naive in this context - it makes more sense applied to VM sizing. It applies to a single tasking system, or one where the user treats it as such. When a user is frequently switching between active tasks and, critically, starting new ones, then having free memory helps avoid swapping. Anyone who's run a modern multitasking OS at close to RAM limits knows what that feels like. At the time I took that snapshot my system had a huge cushion, but I'm often running that stuff plus one or two 2GB VM images and under those circumstances it gets tight. – Tim – 2012-11-29T19:37:23.953

Separate point, so new comment. "It's just not worth the effort of making it free." So Mac OS isn't actually freeing memory when processes exit (or call free(), directly or indirectly) unless the system needs that memory? That would explain it. And yet, when I quit open programs I do see active memory go right down. So it's freeing some of it some of the time. – Tim – 2012-11-29T19:38:18.773

@TimKemp: It depends whether it's possible for some other process to use the memory again or not. If it's impossible, then the OS must make it free. If it is possible, for example if it contains clean pages faulted in from files on disk, then it won't be made free. – David Schwartz – 2012-11-29T20:36:41.833