5

Ever since I came back to Firefox a year or so ago I have been facing the same issue over and over again - the browser just keeps eating up my memory. The problem arises from (maybe the incorrect assumption) that once a user closes a tab the browser would release the allocated memory for that tab. Of course Firefox as many others have some caching running in the background. Re-opening recently closed tabs also seems to have something to do with this. So this memory release doesn't happen as fast as the user might wish for it to happen.

I've read in many forums (including Mozilla's) that if another process requires the allocated memory that Firefox doesn't need right now the OS (in my case Debian Jessie) will take some from the browser and give it to that other process. Yes, this should indeed happen but it doesn't. Firefox keeps eating up resident memory and once it's almost all gone (like 3.6GB or so out of 3.8GB) the swap kicks in. All this results in an extremely painful browsing experience. Closing tabs doesn't do any good. Even when I close Firefox the allocated memory is still there for quite some time.

I would like to know if it is possible to force the OS to reallocate all the memory (including swap) that a process has been using (even if no other process requires that memory right now) but is now closed.

EDIT:

As requested here is the result of calling free (used the -h parameter for readability purposes) before and after Firefox is shutdown:

Before:

               total       used       free         shared       buffers        cached

Mem:           3.7G        3.6G       134M         6.8M         5.0M           166M

+/- buffers/cache:         3.4G       306M

Swap           3.7G        2.8G       916M

After:

               total       used       free         shared       buffers        cached

Mem:           3.7G        2.9G       856M         4.8M         12.0M          179M

+/- buffers/cache:         2.7G       1.0G

Swap           3.7G        2.7G       998M

As you can see some slight decrease is noticeable however it is nothing compared to the overall memory using (both resident and swap) even 20-30 minutes after the browser was closed. Beside Firefox I have nothing else started except the usual Debian processes and a couple of panel applets (weather, CPU+HDD+Mem monitoring, network monitoring etc.) which don't take a lot of memory and I can barely notice their values with htop. All I did was basically leave the browser opened the whole day and close/open tabs. I have to admit that there are a lot of tabs in my session however I upon start (and later on) I only load a few of those. My guess is that probably even when not loaded with content the tabs takes a lot of memory. However this doesn't explain why after closing the browser I have such high memory allocation. It is in fact so high that sometimes I cannot shutdown my system properly and have to do a cold shutdown.

  • 2
    In short, no. Firefox has had historically memory leaks. Firefox lately sucks, and I wonder when they will include in it a coffee machine, and a spreadsheet. Change browsers. – Rui F Ribeiro Jan 23 '16 at 8:02
  • Chromium has similar problems. I'd also be interested in the answer to this question, though I suspect it is no. I've found an extension called "The Great Suspender" for Chromium, which helps. Check if there is one for Firefox. – Faheem Mitha Jan 23 '16 at 8:37
  • 1
    firefox has an internal url about:memory that has a button minimize memory usage, and another url about:cache that may have some info. In the about:config page type the search term cache and you will see lots of settable options to investigate further. – meuh Jan 23 '16 at 8:46
  • Thanks for the tip @meuh however it seem that neither of the three options for freeing memory (global garbage collection, cyclic and sending "heap-minimize" notifications) results in something. Maybe these are just dummies? LOL Will have to investigate further on that. – rbaleksandar Jan 23 '16 at 11:06
  • @rbalel... I can confirm this - the memory-freeing buttons do nothing - except for the "minimize memory usage" - which reduces memory for about 3 seconds, after which it goes back to where it was - including (from the report), holding memory for long-closed pages. Will mozilla ever make a great browser like Version 3.5 again? I doubt it. They seem committed to making it more bloated and harder to navigate with every release. – JosephK Nov 13 '16 at 12:38
1

The short answer is no: once an application has allocated memory, and used it, it "belongs" to that application, and unless that application releases it nothing else can reclaim it. (This isn't as simple as a call to free() though since that just returns memory to the individual application's pool, not to the system.)

Swap is supposed to help with this: once physical memory is full, the operating system can move seldom-used pages of memory to swap. If the real working-set is bigger than physical memory this just results in thrashing: memory is moved to swap and back all the time, and the system can't do anything useful.

On Linux as a last resort the OOM killer will step in and kill processes to reclaim their memory.

It's odd that you don't see memory recovered as soon as Firefox stops; perhaps the Firefox process is taking a while to actually quit, after its window is gone (check with ps or your task manager). When a process stops, all its allocated memory is freed and becomes available for others.

  • Yes, I know how free() works and what thrashing is. :) Still the memory remains allocated (maybe deallocates but just a tiny bit). I've checked with htop and all iceweasel processes were gone. This is one of the reasons why I posted this question. Because this sort of situation doesn't make any sense from a developer's point of view. – rbaleksandar Jan 23 '16 at 20:52
  • How do you measure that the memory remains allocated? – Stephen Kitt Jan 23 '16 at 21:14
  • Htop give a pretty neat overview. For the swap I also use cat /proc/swaps (can also use sudo swapon -s but why bother enter password :D). Xfce does provide a monitoring tool for the panel too, which (so far) has been true to its purpose. Also when there is too much resident memory allocated + swap is almost full (Firefox again...) you can most certainly fill the sluggishness in your system. Usually if both reach too high levels (but only when Firefox was the reason) I'm also unable to shutdown properly let alone suspend to disk. – rbaleksandar Jan 24 '16 at 0:57
  • What does free say, just before killing Firefox and just after (once there is no firefox process running, as verified by ps -C firefox)? – Stephen Kitt Jan 24 '16 at 14:45
  • I've updated my answer. – rbaleksandar Jan 25 '16 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.