16

I am primarily using Firefox as my web browser. I have noticed that after some tabs having been opened and closed the memory usage of Firefox becomes larger and larger.

This fact often leads me to crash it (deliberately using the task manager) and to open it again selecting only some of the tabs I need. There are cases where I open all my previously open tabs. The funny thing is that even in this case, the memory usage is by far less than what it was before shutting Firefox down.

So my question is why is this happening? Why does the closing of the tabs not help (at least not that much)? Is there a way to reduce the memory usage without shutting Firefox down?

ks1322
  • 445
  • 5
  • 19
Eypros
  • 339
  • 1
  • 3
  • 11
  • 1
    When you say "memory", what precisely do you mean? Resident set size? Commit charge? Virtual address size? How are you measuring and what operating system are you using? Also, why do you deliberately crash it? Are you having some kind of actual issue? Or do you prefer that RAM be wasted than used? – David Schwartz Jul 29 '14 at 09:32
  • 1
    Sorry, about the missing information. I am using win7, I am referring to RAM memory, I am measuring simply observing the task manager tab so the memory estimation may not be too accurate. The fact is that firefox sometimes uses upto 2Gb of memory which does not seem reasonable for the number and content of tabs being open. – Eypros Jul 29 '14 at 09:45
  • Which tab --"Working Set (Memory)"? – David Schwartz Jul 29 '14 at 10:04
  • The tab "Memory (Private Working Set)" – Eypros Jul 29 '14 at 10:45
  • Does this memory behavior happen if you run Firefox without any plugins? – Ramhound Jul 29 '14 at 10:58
  • I haven't check it without plugins to know. But I don't think I am using a large number of them. – Eypros Jul 29 '14 at 11:05
  • 1
    I can recommend small addon that allow restart firefox in easy way. https://addons.mozilla.org/ru/firefox/addon/restartless-restart/ – Mikhail Moskalev Dec 21 '14 at 12:00
  • Thats because browsers suck! I myself has put firefox into a linux virtual machine and had limited the ram to 128. the browser now is using the swap for its usage and Im laughing at how firefox is trying to get more memory. firefox , suck it. – TechLife Apr 30 '15 at 08:08
  • 1
    Possible duplicate of [Is there a way to reduce the memory usage of Firefox?](https://superuser.com/questions/24803/is-there-a-way-to-reduce-the-memory-usage-of-firefox) – YetAnotherRandomUser Feb 28 '18 at 20:38

4 Answers4

6

Enter about:memory in the address bar. Click 'Minimize memory usage'.

https://support.mozilla.org/en-US/kb/firefox-uses-too-much-memory-ram

David Marshall
  • 7,200
  • 4
  • 28
  • 32
  • +1. I don't know if it will solve all my problem but it was useful anyway, so thanks. – Eypros Jul 29 '14 at 09:49
  • 10
    This completely fails to answer the primary question asked. "Why does my Firefox memory usage keep rising with use and never returns to the initial level?" – David Schwartz Jul 29 '14 at 10:48
  • And, by the way, you would only want to do this if you were testing or benchmarking. It just forces your system to waste memory that it was using, even if it doesn't need to. (It does it automatically if it needs to, the people who write Firefox aren't stupid and wouldn't make you senselessly hit a well-hidden switch just to get things to work better.) – David Schwartz Jul 29 '14 at 10:48
5

The first thing I would suspect is that some of plug-ins leak memory or use it a lot.

For example, AdBlock Plus often causes Firefox to increase memory usage significantly. The reason is that it injects large style sheets into every frame. (Ghostery is a more memory-efficient alternative, although it serves a different purpose.)

So, as suggested in the comments, if memory usage doesn't seem reasonable, try disabling all plug-ins and see if this helps.

Roman Boiko
  • 151
  • 2
  • 4
  • 2
    @screener suggested an alternative that serves the same purpose as AdBlock, https://addons.mozilla.org/firefox/addon/ublock/ – Roman Boiko Apr 22 '15 at 20:39
  • This answer shows you how to find which addons are taking up the most memory: https://superuser.com/questions/5939/how-to-determine-which-firefox-add-ons-are-using-the-most-memory – YetAnotherRandomUser Feb 28 '18 at 20:46
2

If you need the RAM for other purposes, just restart Firefox. It will minimize it's memory usage, too.

You can even say to Firefox that it does not have to load all pages upon restart:

Firefox button -> Options -> Tabs -> Don't load tabs until selected

Also, I have noticed a high memory usage from Adblock Plus. Adblock Edge does not seem to have this issue. Disabling Adblock Plus also frees memory.

Smile4ever
  • 259
  • 2
  • 11
0

RAM cannot be saved for later. Your only choices are to use it or waste it. A system with 8GB of RAM can't use 4GB today in order to use 12GB tomorrow.

So, simply put, Firefox is using more memory because the alternative would be to waste that memory. It is not returning to the initial level because it would take effort to do so and there would be no benefit to expending that effort.

The fact is that firefox sometimes uses upto 2Gb of memory which does not seem reasonable for the number and content of tabs being open.

It's perfectly reasonable if the alternative is to have some of that RAM be wasted and holding no data whatsoever. At a minimum, it allows Firefox to use up to 2GB of memory without having to allocate any more memory, which is a win. Freeing and allocating memory takes effort. Smart systems only expend effort when there's some expected benefit. They certainly don't do work that they'll probably just have to undo later.

Modern operating systems go out of their way to have as little free RAM as possible. Free RAM is forever wasted. If you had 1GB free for the last hour, you gained no benefit whatsoever from that 1GB in that past hour. If you're thinking, "I want that RAM free now so I can use it later", forget it. You can use it now and use it later. There's no painful tradeoff to make here.

David Schwartz
  • 61,528
  • 7
  • 100
  • 149
  • 1
    What do you mean waste it? I was thinking more like releasing the memory that is not used any more. How much effort would it need to release the unused memory? – Eypros Jul 29 '14 at 09:50
  • 2
    @Eypros It's not "unused memory". It's used memory. It could be released, but then the memory would be wasted. Instead of holding possibly useful information, it would hold nothing useful. What would be the point of going through effort to waste memory? (There are ways to make Firefox do this, but they're only useful for measuring and testing. They make performance worse. Firefox will release memory automatically if that would provide a benefit. The people who wrote Firefox aren't fools. They keep memory in use if, and only if, that makes sense.) – David Schwartz Jul 29 '14 at 09:54
  • 7
    Maybe we are entering a philosophical conversation about what is useful. From my point of view I cannot use the memory holding "possibly useful information" as you mentioned since it's allocated by firefox. So I could just get an out of memory message from other application I am using. – Eypros Jul 29 '14 at 09:58
  • 1
    @Eypros Is your issue is that you are getting out of memory messages? If so, you should say so. How much RAM do you have? What are your page file settings? (The behavior you describe in your question is expected and correct. Getting error messages is not. That probably means something is going awry. The OS and Firefox should cooperate to manage memory reasonably.) – David Schwartz Jul 29 '14 at 09:59
  • @RomanBoiko Why does "*Firefox is using more memory because the alternative would be to waste that memory*" not answer the question? – David Schwartz Nov 10 '14 at 03:21
  • I do agree that Firefox is unlikely to use memory without a reason, but its plug-ins aren't always optimized as much. You did provide an answer, thus I've removed my previous comment. – Roman Boiko Nov 11 '14 at 20:27
  • 1
    The performances bootleneck is NOT the memory in use but the CPU usage... David Schwartz is right to say that unused memory is waste memory. That's why the so-called "memory optimizers" by "cleaning" ram decreased performances. Read this: http://windowsitpro.com/systems-management/memory-optimization-hoax from Mark Russinovich (MS Technet Sysinternals) :-) – climenole Dec 19 '14 at 06:25
  • Yes, unused memory is waste. But Firefox sometimes become unreasonable huge (4 Gb for example). Then even close of Firefox itself take long time, up to minutes. – Mikhail Moskalev Dec 21 '14 at 12:02
  • 2
    -1. We multitask all the time, at least, *I* do. Freeing up memory is beneficial for other applications. I saw systems run out of memory (literally, killing a process), or do heavy swapping. Firefox is (or the plugins are) not a good a citizen when memory is scarce. – Karoly Horvath Jan 18 '15 at 17:18
  • @KarolyHorvath You are wrong. Freeing up memory for other applications is inefficient because the memory has to be made free only to make it used again. It is more efficient to directly transition the memory from one use to another without making it free in the middle. Modern operating systems do this very efficiently, and that way it goes from one beneficial use to another beneficial use with no waste. No memory is wasted by being free, and no CPU is wasted by making something free just to have to make it unfree. – David Schwartz Jan 20 '15 at 04:57
  • 5
    @DavidSchwartz: this is complete nonsense. what the hell is "directly transition the memory"? if memory is scarce, one application has to give so another can take (the alternative is the dreaded swapping..). "Modern operating systems do this very efficiently" - do what?? they can get rid of code and library pages because they can be re-fected, they can play with the FS cache pages, but cannot take away memory that's normally used (e.g.: firefox storing a closed tab or images so they can be opened faster). – Karoly Horvath Jan 20 '15 at 11:09
  • @DavidSchwartz: and just for the record, I'm *not* saying that speculating that saved memory that can be used later is *always* a bad idea (hey, that's why we have FS cache). Sometimes or often it works. But saying that it's always beneficial and there's no point being a good citizen is.. well, ridiculous. – Karoly Horvath Jan 20 '15 at 11:26
  • @KarolyHorvath I'd be happy to continue this conversation with you elsewhere. – David Schwartz Jan 20 '15 at 20:39
  • @DavidSchwartz: me too. But don't you want to at least explain what you meant here? – Karoly Horvath Jan 22 '15 at 17:22
  • @KarolyHorvath I believe I already have. It seems that you don't understand how memory management works in a modern OS, and so think that I am wrong when I'm not. You simply don't understand how memory can be directly transitioned from one use to another without the pointless requirement that it bade made free just to be made unfree. – David Schwartz Apr 13 '15 at 05:56
  • @DavidSchwartz: I think I understand it perfectly well. I explicitly mentioned all the main concepts modern OSes do to manage memory (please *tell* me if I missed something important). I also explicitly said that when memory is a scarce resource (e.g.: 1 or 2G with several competing applications), you have to be a good citizen otherwise the only thing the OS can do is to page the memory to disk (and in my experience, simply reloading the pages from the net is faster than trying to refetch pages from the disk). – Karoly Horvath Apr 13 '15 at 06:10
  • 2
    @DavidSchwartz: I also explicitly asked you to tell me what you mean by "directly transition", which you failed to do. – Karoly Horvath Apr 13 '15 at 06:10
  • @KarolyHorvath I did, "transitioned from one use to another without the pointless requirement that it be made made free just to be made unfree". For some reason, I can't move this to a discussion. And the OS only needs to page the memory to disk if it's not discardable. – David Schwartz Apr 13 '15 at 06:11
  • 2
    What's that transition? And how on earth are you going to do that when you don't have FREE memory? – Karoly Horvath Apr 13 '15 at 06:11
  • @KarolyHorvath That's the primary memory management technique all modern OSes use. Making memory free is a last resort used only when there's no possible way to keep the memory in use. Memory doesn't need to be free to have its use changed. Modern OSes make memory free only when they have no other choice. – David Schwartz Apr 13 '15 at 06:12
  • Well, I don't see the browser making these pages discardable, because the OS doesn't discard them. Can I ask you when was the last time you used the browser on a machine with scarce memory? You sound so confident, surely you have first-hand experience... – Karoly Horvath Apr 13 '15 at 06:13
  • 11
    -1 for exactly the same reason as @KarolyHorvath. On a 4 GB machine (which is only "less-that-average" nowadays), FF taking 2.5 GB of *resident* memory (I'm on Linux) is unreasonable, because it *takes memory away from other applications*. When I close several tabs, I expect FF to release the now unused memory, so that other applications, or the kernel itself for that matter (which likes to cache aggressively, greatly increasing overall performance) can use it. This is the archetypal developer/sysadmin dispute, if you don't need the memory anymore, release it, you're not alone on that system. – MoonSweep Apr 19 '15 at 22:02
  • @MoonSweep Applications don't take memory away from applications. The OS decides which applications get physical memory, and if it gives the memory to firefox, it's because that's what it thought was best. – David Schwartz Apr 20 '15 at 02:48
  • 1
    @DavidSchwartz: you're nitpicking on technical details. if the OS decides to give that memory to firefox, then firefox takes away that memory from the other applications. – Karoly Horvath Apr 20 '15 at 06:13
  • @KarolyHorvath Right, but the OS isn't stupid. If would only do that if it makes more sense for Firefox to use that memory than the other applications. – David Schwartz Apr 20 '15 at 06:29
  • @DavidSchwartz: the OS *is* stupid. it probably uses some simple heuristic. it works most of the time, but in this case fails spectacularly. – Karoly Horvath Apr 20 '15 at 06:34
  • 8
    Downvote for one of the stupidest ideas around: "Let's waste memory for fear it will go unused" – lemonsqueeze May 11 '15 at 20:26
  • @lemonsqueeze Leaving memory free wastes it. Using memory, when the alternative is leaving it free, is *not* wasting it. – David Schwartz May 11 '15 at 21:43
  • @KarolyHorvath It's very common for people to think that all the experts are wrong about something and that they know better. But it's very rarely correct. Modern operating systems have very finely tuned and carefully designed memory management systems and they are constantly looking for even the smallest performance and efficiency edge. This has lead to a significant reduction in the amount of wasted effort spent making memory free just to make it used again and the more efficient approach of just keeping the memory in use unless there's no choice. – David Schwartz May 11 '15 at 21:46
  • It's like listening to a looped tape record. after a while, it really gets annoying. – Karoly Horvath May 11 '15 at 23:43
  • @KarolyHorvath I don't know what else I can do but keep correcting people's mistakes. For example, your last point, "*if the OS decides to give that memory to firefox, then firefox takes away that memory from the other applications*" is wrong. The OS doesn't (typically) take memory from applications to give to the application, it typically takes memory for non-application uses such as disk and filesystem metadata caches. I don't care if you personally wish to be wrong, but I do feel it is obligatory for me to correct erroneous statements that others might believe. – David Schwartz May 11 '15 at 23:46
  • 1
    Virtual memory operating systems do in fact try to keep some memory free. When memory fills up, a background "paging daemon" or some such entity beings to swap out least recently used pages to disk. This free memory allows the OS to satisfy future allocation requests much faster than if nothing had been done proactively. **You also can't save disk I/O bandwidth in order to have more in the future!** If the I/O is idle now, you can swap things out in parallel with computation in order not to suffer a delay later. Of course "free" memory can be used for a cache that is easily discarded. – Kaz Aug 10 '15 at 18:50
  • @Kaz You can write information in memory to disk early so that you can discard it later. You don't need to make the memory free to do this and generally it's preferable not to. Modern operating systems only need to make memory free for one purpose -- to have memory that can be allocated in contexts where it's not possible to make more memory free, such as from interrupt contexts. On a modern system, this requires about 20 to 64MB to be free, and that's it. (But this is the answer to the question "why is my system using swap when it's not under any memory pressure". It swaps early too.) – David Schwartz Aug 12 '15 at 07:31
  • 2
    @DavidSchwartz Yes; so pages that are written to swap and marked "not dirty" are quasi-free. They are part of the virtual footprint of the application, but can be put to some other use at a moment's notice. But, if the application isn't a bloated pig with a huge memory footprint, then writing out those pages to swap, whether early or late, is not necessary in the first place. Fact is that because Firefox bloats up to a huge VM size due to fragmentation and leaks, when memory is needed for something else, that bloat has to be swapped out. That makes machines slow. – Kaz Aug 12 '15 at 19:45
  • 7
    You seem to be arguing that it's okay for Firefox to bloat up to 2Gb because that memory is just swap and so other programs are not prevented from having that 2Gb. This is false. Most of that 2Gb is dirty pages which have to be flushed. Out. Moreover, when Firefox decides to run some garbage collection on that cruft, it has to be paged back in: and that will happen in some random order that causes seeks all over the place on a conventional spinning hard drive. Not writing 2Gb to disk and reading it back is demonstrably more performant than doing so. – Kaz Aug 12 '15 at 19:50
  • In a typical garbage collected heap implementation, the *entire heap* is touched regularly (to find garbage), and thus none of it can be paged out. If Firefox decides to spend say 1GB on a garbage collected heap, it will use 1GB of physical memory until it destroys that heap. – user253751 Dec 20 '15 at 20:37
  • It seems that you're taking a theoretical and philosophical stance to people who are experiencing practical problems. When Firefox exceeds a certain amount of RAM used, it becomes unusable, forcing a user to close or forcibly crash the browser. The natural line of thinking is that Firefox has a problem after it gorges on RAM, so if you manage the RAM, the browser will operate properly. – YetAnotherRandomUser Feb 28 '18 at 20:28
  • 1
    @YetAnotherRandomUser The lack of an understanding of what's actually causing the problem leads to huge amounts of wasted time and effort and the inability to solve the practical problem. If you read the original question, you'll notice that it doesn't describe any practical problem AT ALL. This misunderstanding is so thorough that the OP is asking us to solve a practical problem without even saying what symptoms he's experiencing. If the OP was trying to describe a practical problem, he clearly didn't have the theoretical knowledge needed to do so. Hence why I tried to provide it. – David Schwartz Feb 28 '18 at 21:11