You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Lion - Memory Usage Problems

Why is Lion using all 4GB of RAM running Mail, Safari (2 tabs), and iTunes? Snow Leopard was bad enough at handling memory, eating up every available byte and Lion seems to be arbitrarily using even more RAM. Windows 7 has zero problems handling RAM, there's no reason OS X shouldn't be able handle memory properly.


Can someone explain what Apple is doing here? I'm at a total loss. For users who just need Safari, Mail, and iTunes... I guess this works. But how am I expected to reliably run Logic, Final Cut, or Aperture with OS X using every available resource for Web Surfing, E-mail, and Music. This is totally unacceptable for a multi-million dollar software company greated towards professionals as well as consumers.


The following responses are not acceptable by the way:


  • Buy more RAM - I did that already, it will eat up 2/4/8GB, doesn't matter. Not to mention Apple still sells numerous 2/4GB confirgurations.
  • Buy a newer/more powerful Mac - this is a improper handling of memory issue, not a hardware issue.


I'd really love some insight into this. Thanks for reading.

MacBook Pro, Mac OS X (10.7), 13" (late-2009)

Posted on Jul 21, 2011 5:45 AM

Reply
957 replies

Aug 9, 2011 8:22 AM in response to ayrtonoc

Plus, I understand "Inactive" can be made available but Apple's own Activity Monitor shows "Inactive" memory as used memory, its not readily available without a performance decrease.


I don't understand why anyone would believe that any "paging" is okay when the Mac Developer Library and Apple's Help Menu state that it is not desired.

Aug 9, 2011 8:33 AM in response to mightymilk

Anyway, reading around it seems that one of the possible culprit for the Safari memory leak problem is AdBlock. I checked this myself. A couple of hours ago I disabled AdBlock and reloaded all tabs. It freed some memory. Then I restarted Safari and since then my total memory usage is below 2GB (1.88GB to be precise). The most interesting thing is that the values of Free memory and Inactve memory inverted: 260MB Inactive, 870MB Free. 14 tabs open.


Instead of it I am using GlimmerBlocker (http://glimmerblocker.org/). It works as a local web proxy for ads. It is nearly as effective of Adblock. Its advantages are that it is an independent application that works at URL level, so it does interfere directly with the browsers and it removes the enbedded ads in the flash videos!!


It may not be the solution but it is worth a try. I also filed a bug report in the Adblock site, just in case.

Aug 9, 2011 8:38 AM in response to Michelasso

Michelasso wrote:


Anyway, reading around it seems that one of the possible culprit for the Safari memory leak problem is AdBlock. I checked this myself. A couple of hours ago I disabled AdBlock and reloaded all tabs. It freed some memory. Then I restarted Safari and since then my total memory usage is below 2GB (1.88GB to be precise). The most interesting thing is that the values of Free memory and Inactve memory inverted: 260MB Inactive, 870MB Free. 14 tabs open.


Instead of it I am using GlimmerBlocker (http://glimmerblocker.org/). It works as a local web proxy for ads. It is nearly as effective of Adblock. Its advantages are that it is an independent application that works at URL level, so it does interfere directly with the browsers and it removes the enbedded ads in the flash videos!!


It may not be the solution but it is worth a try. I also filed a bug report in the Adblock site, just in case.


I experienced the same results after disabling AdBlock Plus, as mentioned in a previous post. Anyone having problems should experiment with disabling different add-ons or extensions all together to see how it affects your performance and memory consumption. Also try disabling Java, and record your results.

Aug 9, 2011 9:46 AM in response to Michelasso

My idea was that the kernel, once it is low in free memory, first frees memory from the inactive memory list and only if none is available it starts paging out.

It isn't quite that simple. If the content of a page of inactive memory has not changed since it was paged in it can be used for other processes without first paging it out. The memory manager constantly monitors for changes in RAM, so it takes almost the same time to decide if a page of inactive memory can simply be discarded & used as active memory as it does to use free memory.


This happens much faster than Activity Monitor can track. This is also true for iStat & similar third party utilities -- the info all comes from the same code in the OS that queries the kernel for memory use data. There is no way around this: the more often it samples that data, the more system resources that uses. At high enough sample rates to see everything the system would be doing almost nothing else, causing every other process to slow to a crawl.


The inactive memory should be a sort of cache for the pages on the disk that have already been read.If a process requests a page that had already been allocated and it is present in the inactve memory it reallocates it from there.

That is exactly what it does. If a process needs a page that has been marked inactive (& its data has not changed), it is just marked as active & immediately used.

Otherwise from the free memory.

??? I don't know what you mean by that. As far as the memory manager is concerned, free memory is empty since it is no longer tracking its contents.

If the free memory is below the low water mark, OS X should free a bunch of pages from the inactive memory. I have been monitoring the memory usage in the last few days and as far as I could check none of that happened.

It frees up only as many pages of inactive memory as it needs. And it does this much faster & more often than you can track during normal operation.


I also disabled the virtual memory manager (dynamic_pager) for testing...

Note that using "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist" does not now permanently disable the dynamic pager. From the man page for launchctl:


-w Overrides the Disabled key and sets it to false. In previous versions, this option
would modify the configuration file. Now the state of the Disabled key is stored
elsewhere on-disk.


If VM really is disabled, the following command should not list any files after a restart:


ls -lh /private/var/vm/swapfile*


Under normal conditions, a single "swapfile0" should be created at startup time. Its size may vary depending on how much RAM is installed. More consecutively numbered swapfiles that will gradually increase in size will be created as needed to support VM, but their contents will vary since their pages are reused & new ones are created only when the existing ones can't hold everything VM requires. The total of all these files represents the maximum VM used since startup, but current VM use may be much lower.

Aug 9, 2011 10:49 AM in response to Michelasso

Michelasso wrote:

Anyway, reading around it seems that one of the possible culprit for the Safari memory leak problem is AdBlock.

If Adblock (or any other extension or web browser plug-in) is causing excessive memory use, that does not mean there is a memory leak in Safari or Lion. In fact, there may be no memory leak at all.


A memory leak is a specific kind of programming error that prevents a segment of memory already allocated to a process from being available to the running code, which causes the process to request more & more memory each time it uses that routine. But other things besides memory leaks can cause memory use to shoot up, especially when an application process calls routines not part of its own code package. If that routine wants to use a big chuck of the app's allocated memory (rightly or wrongly), the app has no choice besides asking the OS for more to run its own routines.

Aug 9, 2011 11:29 AM in response to R C-R

Sorry, I don't understand how to break the quoted test to write in the middle of it. So I'll just reply to this one.

R C-R wrote:

If the free memory is below the low water mark, OS X should free a bunch of pages from the inactive memory. I have been monitoring the memory usage in the last few days and as far as I could check none of that happened.

It frees up only as many pages of inactive memory as it needs. And it does this much faster & more often than you can track during normal operation.

I've read this argument before. True, in 1 second time frame who knows what really happens. But here we are talking about activities visible to the human eye (by mean of a monitoring tool, obviously) that do not really fit with what one think should be the most efficient behavior.


Like now for example. I just streamed a movie to my PS3 and the what I call "available memory" (about 1GB) still kept constant. Only that the Inactive memory raised to 980MB and the Free memory went down to 20MB. The swap area was reported to be 0B. So I decided to open Chrome on top of that and load all preferred tabs. It freed some memory (100MB or so) and filled a swap area of 320MB (page out).


Closed Chrome, the swap area went down to 37MB and the Free Memory up to 753MB!! Plus 179MB of Inactive memory. What.. the .. beep?!


That means that Lion paged out 320MB, allegedly from Inactive memory, gave it to Chrome, and once Chrome was closed it decided that not only the paged Inactive memory was not needed, but also another 1/2 GB on top of that could be freely given back to the kernel. Couldn't it just free it as soon as it was needed? Did it have to add hard disk writes overhead? I repeat, to me this is either a bug or a very dumb decision. A new active process should have priority over some forgotten data that might be useful in the future.


BTW to disable the virtual memory I use this command:


sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist


After that the dynamic_pager process disappears:


BlueMoon:Scripts $ ps -ef | grep dyn

0 73 1 0 2:57pm ?? 0:00.17 /sbin/dynamic_pager -F /private/var/vm/swapfile

502 809 235 0 8:24pm ttys000 0:00.01 grep dyn

BlueMoon:Scripts $ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Password:

BlueMoon:Scripts $ ps -ef | grep dyn

502 815 235 0 8:24pm ttys000 0:00.00 grep dyn

BlueMoon:Scripts $


I think at this point there is no more virtual memory. Not sure how it works.

Aug 9, 2011 12:11 PM in response to mightymilk

When I try to watch YouTube video in full screen, it will have a consistent stutter. This performance issue happens after the iMac has been running for many hours. My workaround is to restart the machine and then I'll have smooth playback. After hours of use, the same thing will happen. What I found interesting is I when I switch to Firefox, no AdBlock, I still have the consistent stutter until a restart leading me to believe there may a 'leak' or some other issue that could be started by Safari and extensions and then affecting over-all performance.


I've deleted AdBlock, restarted and will watch Memory usage for the day.


I usually have iTunes, Mail and Safari open in their own Spaces, full screen.

4 GB ram, iMac 2.8 GHz Intel Core 2 Duo. Page outs stay at 0 bytes even after hours of use. Safari Web Content Real Memory is at 205.5 MB after 2 hours.


Quick question: My VM size says 190.13 GB but I only have 32 GB available on my HD?

Aug 9, 2011 12:42 PM in response to John Kitchen

John Kitchen wrote:


Atomic Al, if you fill your HDD up beyond 80%, you have a risk of significant file fragmentation, leading to performance issues. The further you go, the higher the amount of fragmentation, it grows almost exponentially.

But this performance issue only started with Lion and Safari 5.1. How many GBs larger is the Lion upgrade over Snow Leopard? I had only about 5 GB left on my Snow Leopard build and then increased it by deleting another 25 - 30 GB of 'flotsom' a couple of weeks after the upgrade.

Aug 9, 2011 1:08 PM in response to Atomic Al

I had only about 5 GB left on my Snow Leopard build and then increased it by deleting another 25 - 30 GB of 'flotsom' a couple of weeks after the upgrade.


Absolutely agree with John's advice - the OS cannot operate efficiently or properly with such little HD space. You are looking at problems and I have no idea how it managed to run at all with only 5 GB. You need to do some serious HD cleaning - moving space hogging files off your HD onto an external (don't forget to delete them after copying and empty the trash).

Aug 9, 2011 1:24 PM in response to R C-R

R C-R wrote:


If Adblock (or any other extension or web browser plug-in) is causing excessive memory use, that does not mean there is a memory leak in Safari or Lion. In fact, there may be no memory leak at all.


A memory leak is a specific kind of programming error that prevents a segment of memory already allocated to a process from being available to the running code, which causes the process to request more & more memory each time it uses that routine. But other things besides memory leaks can cause memory use to shoot up, especially when an application process calls routines not part of its own code package. If that routine wants to use a big chuck of the app's allocated memory (rightly or wrongly), the app has no choice besides asking the OS for more to run its own routines.

No one is denying that. The issue is that whoever it is other than keeping requiring chunks of memory it seems to forget to release them. Which would be by definition a memory leak.


In my case it should be Adblock. After disabling it Safari is using less than half the memory needed the previous days. Before just watching at the memory monitor the mem size of the Safari's WebProcess (the new sandbox, I suppose) was raising of 1MB every second or so.


However this is only part of the problem. The supposed memory leak simply exposes what is possibly a bug in the memory management system of Lion. As previously discussed, the fact that by design Lion pages out instead to free [plenty of] inactive memory would be ********. Personally I wouldn't probably ever noticed it if it wasn't for Safari growing out of the limit in memory size. With SL I rarely needed more than 2.5GB and that was running virtual machines. Still w/o much paging, tho.

Aug 9, 2011 1:50 PM in response to babowa

babowa wrote:


Absolutely agree with John's advice - the OS cannot operate efficiently or properly with such little HD space. You are looking at problems and I have no idea how it managed to run at all with only 5 GB.

But it did run with only 5 to 7 GBs of free space for over a year anyway. I rarely had the spinning beachball or poor performance with DreamWeaver, Photoshop, iTunes and Safari running. I archived (to an external) and deleted files to see if that would help.


I'm following this thread because I think there is a leak somewhere and I think Safari (maybe the extension) has something to do with it. My Macbook Pro right beside me is showing the same symptoms with the Web Content Memory creeping up and it has lots of free HD space. It was also running AdBlock and would start to beachball with many tabs open.

Aug 9, 2011 1:58 PM in response to Atomic Al

Well, you've been fortunate. As for disk space - or mentioning a "leak" - you do know that there is a new feature called snapshots (part of TM) on laptops - makes continuous backups when not home (home meaning not attached to a TM drive) which will not be wiped until TM catches up. So it could be that is what you're experiencing.


http://web.me.com/pondini/AppleTips/DiskSpace.html

Aug 9, 2011 2:15 PM in response to mightymilk

R C-R imagine if you will thousands of pages here, all filled with people describing this basic phenomenon: upgrade to Lion and Safari 5.1 is consuming what seems to be large amounts of memory, and under normal usage am experiencing slowdowns that had not experienced before, the slowdown is reflected in increased memory usage in Activity Monitor. Would you therein continue to unpack the complexities allocation, purging, consumption, estimation, in what continue to be somewhat interesting, albeit esorteric and ultimately useless posts. To you and everyone else who carries on in that way, what I believe people want are solutions. They want to be able to use their machine in a way their consider normal and not have it slow to a crawl. If you cannot offer them any, why not say that? Is it really meaningful for you to essentially attempt to persuade people that what they see is not reality and to essentially defend what may actually be errors on Apple's part?

Lion - Memory Usage Problems

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.