# Firefox is leaking memory on my system



## dieselriot (Sep 21, 2018)

I recently reinstalled FreeBSD because of issues I couldn't fix (It was constantly panicking, even in SU mode), and now, after rebuilding my whole setup, Firefox is giving me problems. I thought it could be a bug in the most recent version, so I switched to firefox-esr, same results.

The process /usr/local/lib/firefox starts eating more and more RAM when Firefox is in use. Even if I quit Firefox, this process stays and keeps eating RAM. I can't kill it, not even with the root user. It soon gets to the point where my machine can no longer operate properly and I'm forced to reboot. This is an underpowered (for today's standards) laptop with only 1.5G of RAM, so this is a huge deal. 

Has anyone been experiencing anything similar? 

Thanks, everyone.


----------



## Beastie (Sep 21, 2018)

You haven't mentionned what version of FreeBSD you're using? Is it up to date (latest patch level)?

Unless something is seriously messed up, FreeBSD rarely needs reinstalling.

Have you tried other browsers? Even if you don't intend to use them in the long-term, do install a few others, try them for a while and check for similar symptoms.

A 1.5GB memory may not be enough at all if you installed on ZFS, are using a full-bore desktop environment and expect to run such a beast as Firefox (Firebrontosaurus is more like it). Or it may be _more than enough_ if you installed on UFS and are only using a window manager and a few other applications.


----------



## jb_fvwm2 (Sep 21, 2018)

Seamonkey started using more memory with just  a tabs open after a pkg update from a few weeks ago, maybe after the xorgproto switchover... just guessing.


----------



## gnath (Sep 22, 2018)

Firefox takes average 325M of RAM per open tab. Still my 2GB of RAM is good enough for normal use. Building from base up & adding required packages gradually may be a good idea. Can identify the cause of panic.


----------



## Deleted member 48958 (Sep 22, 2018)

jb_fvwm2 said:


> dieselriot said:
> 
> 
> > The process /usr/local/lib/firefox starts eating more and more RAM when Firefox is in use.
> ...



What I've noticed, is that my system started to use much more RAM
while I'm doing regular tasks, like browsing in any firefox based browser,
it happened after upgrade to 11.2, but also may be after some pkg upgrades,
I'm not sure what's causing this.


----------



## gnath (Sep 22, 2018)

Yes earlier system never touched swap with 2GB RAM. Now some time this uses 300-400 M of swap. ( FreeBSD-11.2-RELEASE-p2).


----------



## Deleted member 30996 (Sep 22, 2018)

I've been using www/firefox as my main browser the past couple months and am currently at FreeBSD 11.2-RELEASE-p3. I haven't noticed anything out of the ordinary as far as resource usage with it, but saw this post last night and took note of my system stats before visiting Demonica.

That was almost 7 hour ago, I've had at least 4 tabs open at all times and right about the same as I was when I started, if not to the good 360MB RAM. I have www/palemoon open to post this from now too, since I am still logged in there with Firefox. Mozilla based browsers are all I use.

I've got 8GB RAM. It does show me using 10MB Swap in `top`, but I started it when I saw this post and it was using that much then:


----------



## leebrown66 (Sep 22, 2018)

I have an older workstation FreeBSD-11.1-p6, 4GB RAM, firefox 61.  It's a memory leaker.  I tested this recently after my 12G of swap was up to 89%, closed all 6 firefox instances and swap dropped to 2%.

I'm writing this on QupZilla.


----------



## drhowarddrfine (Sep 23, 2018)

The "my browser leaks memory!" issue arises every time someone has a high memory usage program and usually posted by someone who doesn't really understand what a memory leak is. About 10 years ago this was an issue with Firefox and it quickly went away. I live in the browser and have not noticed any problems but I've been doing testing with Chrome the past two weeks.


----------



## Deleted member 48958 (Oct 2, 2018)

After downgrading to 11.1 this issue disappeared for me,
also it is definitely  doesn't related anyhow to "understanding what a memory leak is", because this problem is very obvious -- RAM and SWAP are *always* almost full, even after closing all applications, and your machine starts to be very slow, you're lucky if you don't have this issue, drhowarddrfine. Also, it seems, it is not a kernel problem, because just changing kernel to 11.1 didn't change nothing -- RAM is always full and SWAP is always almost full, but after installing 11.1 world, the issue gone away for me. Also I reinstalled all packages from "quarterly" repo after downgrade (I used "latest" before), so maybe it solved the problem, I'm not sure what helped exactly. The easiest way to reproduce this issue - while using 11.2, start using some X applications, that use RAM actively, and if your RAM memory doesn't free up then, you have this issue.


----------



## dieselriot (Oct 2, 2018)

Hey folks, although I haven't had time to reply, I was keeping up with this thread.

I'm using FreeBSD 11.2-RELEASE. I don't have a desktop environment installed and I'm not on ZFS. It's just WindowMaker and a dozen dockapps, no compositor.

I was not familiar with the fact that firefox might take >300MB per open tab, in fact I never bothered to check, because I never had this problem. It doesn't take this much on my system for subsequent tabs. I actually tried to fill my RAM by opening like 6 or 7 tabs of heavy websites, but that was not enough and is way out of my usual browsing behavior. After switching to firefox-esr, I went back to regular firefox, which was already a version newer than I was using initially. This issue seems to be happening less frequently, although it could be just coincidence.

When this issue arises, I usually only have two or three tabs open. I capped a moment when this happened in the middle of last week. This time memory was still not full (although almost) when I succesfully closed firefox. Then one of the processes was succesfully killed, but another remained and started going on a RAM binge. I tried killing it multiple times, but it only died after around 4 minutes. The first screenshot is from before closing firefox, the other three are after.

This happened again today and again I was able to reproduce the same behavior, i.e. closing firefox before it fills the RAM. Even after managing to kill all the processes and resource usage going back to normal, my system was still very slow, which leads me to believe that this is not an issue with firefox itself, but a system stability issue that's causing firefox to misbehave.

   

EDIT: Looking again at these screenshots, it seems that the screenshooter processes also both lingered around for a while and are using more RAM in the last screenshot...


----------



## Deleted member 48958 (Oct 2, 2018)

IMO it isn't a problem with firefox, it is a problem with system,
after downgrade to 11.1 using `# freebsd-update upgrade -r 11.1-RELEASE`
I have no problems with www/firefox or www/firefox-esr,
FF works very fine and RAM usage is OK (I use ZFS on this machine).


----------



## dieselriot (Oct 2, 2018)

I stopped using FreeBSD for a couple months until 11.2 was released because in 11.1 the kernel panicked every time firefox started. The crash log confirmed that firefox was the cause. I'm not willing to go back to 11.1, especially when 11.2 supports vdpau, which is very important on a laptop like this one.


----------



## drhowarddrfine (Oct 3, 2018)

dieselriot You had other problems unrelated to Firefox. My web dev company has 10 developers who have been using Firefox continuously since FreeBSD 5.2


----------



## shepper (Oct 3, 2018)

Firefox is an equal opportunity memory leaker: OS/X, Windows, Linux, BSD's it does not disciminate.  It is more a matter of how much leaking you will tolerate in order to access web content in multiple tabs, popups and pop-unders.
For what its worth, Theo de Raadt weighed in:
Chromium vs Firefox
OpenBSD has been able to get chromium to "pledge" while it Failed in Firefox.


----------



## Quarter Wave Vertical (Dec 16, 2018)

I'm running FreeBSD 11.2 with Mate on most of my systems.

In the last few weeks, Firefox has had the habit of first freezing and then crashing.  Eventually, there's only one FF process running and it takes up a lot of the CPU's time, sometimes more than 40%.  That process usually dies after a few minutes.

I thought it was only an 11.2/Mate problem, but I have a laptop with 11.2 and Xfce and Firefox behaves the same on that.

It doesn't seem to matter which circumstances it misbehaves.  I thought it might be associated with a specific website (e. g., YouTube) but that doesn't seem to be the case.  I thought that it might have something to do with me keeping several tabs open but when I tried opening new windows instead of tabs, the same thing happened.  Even clearing the cache after launching it didn't seem to make any difference.

If I have maybe 2 or 3 tabs open, however, it seems to play nice with me.


----------



## fraxamo (Dec 16, 2018)

I'm experiencing the same issue. I'm also running Xfce on 11.2 p5. Before upgrading to FFv64.0, Firefox had always been rock solid for me from FreeBSD 9.0, through 10.x right up to 11.2.

As you mention, the browser freezes before eating up CPU and then crashing. Restarting the browser brings back all tabs, although sometimes I find I have been logged out of any accounts etc. The freeze usually happens for me when I log into one of the larger sites, such as eBay or Amazon.

I don't run any other OS, so can't test whether Firefox exhibits the same issues elsewhere.


----------



## dieselriot (Dec 16, 2018)

This no longer seems to be an issue in 12-RELEASE. Although I have only been using it for a couple of days so I can't tell for sure. My theory is that this is some kind of performance hindering bug affecting certain hardware that slipped into 11.1 and the code was replaced by the time 12 got released. And since firefox is the heaviest application we use it's the one that suffered the most. Just thoughts though, please call me out if this is not plausible.


----------



## sidetone (Dec 16, 2018)

Quarter Wave Vertical said:


> In the last few weeks, Firefox has had the habit of first freezing and then crashing.  Eventually, there's only one FF process running and it takes up a lot of the CPU's time, sometimes more than 40%.  That process usually dies after a few minutes....
> 
> It doesn't seem to matter which circumstances it misbehaves.  I thought it might be associated with a specific website (e. g., YouTube) but that doesn't seem to be the case.  I thought that it might have something to do with me keeping several tabs open but when I tried opening new windows instead of tabs, the same thing happened.  Even clearing the cache after launching it didn't seem to make any difference.
> 
> If I have maybe 2 or 3 tabs open, however, it seems to play nice with me.





fraxamo said:


> I'm experiencing the same issue. I'm also running Xfce on 11.2 p5. Before upgrading to FFv64.0, Firefox had always been rock solid for me from FreeBSD 9.0, through 10.x right up to 11.2.
> 
> As you mention, the browser freezes before eating up CPU and then crashing. Restarting the browser brings back all tabs, although sometimes I find I have been logged out of any accounts etc. The freeze usually happens for me when I log into one of the larger sites, such as eBay or Amazon.



dieselriot may be having this problem with Firefox, but didn't describe it like in the quotes.

Mine started freezing, crashing, then logging me out of accounts. After re-installing or upgrading Firefox, there was a notice which worked.
Put `net.local.stream.recvspace=16384` into /etc/sysctl.conf, and use `sysctl` with this argument to temporarily set it without rebooting. Firefox works smoothly after this. Also, I don't have to go through the trouble of manually killing Firefox operations, after it previously crashing.


----------



## fraxamo (Dec 16, 2018)

sidetone said:


> After re-installing or upgrading Firefox, there was a notice which worked.



Hi, can explain what you mean by this please? Do you mean that the Firefox port/pkg now ships with a notice explaining that this setting needs changing?

Can you also explain what the setting does please? I've tried searching the web for information on it, but I'm not finding much. However, wherever I've found it being set, it seems that the setting 'net.local.stream.sendspace=16384' is also set. So, should I be setting that as well?

For example, this is what I'm seeing on the calomel.org website (although the settings are commented out):

# Increase the localhost buffer space as well as the maximum incoming and
# outgoing raw IP datagram size to 16384 bytes (2^14 bytes) which is the same
# as the MTU for the localhost interface, "ifconfig lo0". The larger buffer
# space should allow services which listen on localhost, like web or database
# servers, to more efficiently move data to the network buffers. 
#net.inet.raw.maxdgram=16384         # (default 9216)
#net.inet.raw.recvspace=16384           # (default 9216)
*#net.local.stream.sendspace=16384   # (default 8192)
#net.local.stream.recvspace=16384     # (default 8192)*

Thanks for your help.


----------



## sidetone (Dec 16, 2018)

fraxamo said:


> Hi, can explain what you mean by this please? Do you mean that the Firefox port/pkg now ships with a notice explaining that this setting needs changing?
> 
> Can you also explain what the setting does please? I've tried searching the web for information on it, but I'm not finding much. However, wherever I've found it being set, it seems that the setting 'net.local.stream.sendspace=16384' is also set. So, should I be setting that as well?
> 
> ...


The notice suggested to increase `sysctl net.local.stream.recvspace=16384` to that value, to that prevent it from crashing. You don't necessarily need to upgrade or reinstall Firefox, but I got that message after doing so from ports. Better yet, you can find this message in /usr/ports/www/firefox/pkg-message. It increases something so it will have room to do functions, and won't crash.


```
On FreeBSD < 11.3 Web Content process may frequently crash due to bug 181741.
If you cannot upgrade try applying the following workaround:

$ sysctl net.local.stream.recvspace=16384
```
Upgrading didn't fix it for me, unless I changed that value. I didn't set `net.local.stream.sendspace=16384   # (default 8192)`: my value for this is still at 8192, and this works. If you want to know more, then you'll have to look up that specific bug.


----------



## Quarter Wave Vertical (Dec 16, 2018)

fraxamo said:


> I'm experiencing the same issue. I'm also running Xfce on 11.2 p5. Before upgrading to FFv64.0, Firefox had always been rock solid for me from FreeBSD 9.0, through 10.x right up to 11.2.
> 
> As you mention, the browser freezes before eating up CPU and then crashing. Restarting the browser brings back all tabs, although sometimes I find I have been logged out of any accounts etc. The freeze usually happens for me when I log into one of the larger sites, such as eBay or Amazon.
> 
> I don't run any other OS, so can't test whether Firefox exhibits the same issues elsewhere.


Thanks.  I thought I was the only one with that problem.

Firefox has been troublesome for me for about the last  year.  When I upgraded it back then, it exhibited some very strange behaviour.  Sometimes I would open a tab or window and the page wouldn't load.  The browser would simply idle as if it was in an infinite loop.

Sometimes, such as for a YouTube video, the page would open but all I got was the audio track with no video.  I could get around that by either opening that same URL again or by opening a tab instead of a window (sometimes the other way around).

This recent behaviour had me concerned.  A few weeks ago, it caused my machine to crash with kernel panics.

I'll try what you suggested and see what happens.


----------



## fraxamo (Dec 17, 2018)

sidetone said:


> Upgrading didn't fix it for me, unless I changed that value. I didn't set net.local.stream.sendspace=16384   # (default 8192): my value for this is still at 8192, and this works. If you want to know more, then you'll have to look up that specific bug.



Many thanks for the explanation and your help.


----------



## sidetone (Dec 17, 2018)

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229893#c0 shows the Firefox related bug that points to https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=181741

It says it's a kernel bug. Setting `sysctl net.local.stream.recvspace=16384` fixes it or bypasses it for Firefox, at least for many.

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=226476#c65 also mentions bug 181741, but it is hardly informative.


----------



## fraxamo (Dec 17, 2018)

I've been pushing Firefox hard for the last couple of hours and so far so good. Yesterday, I could hardly open more than a few tabs without it borking. Looks like this is fixed for me. Thanks again!


----------



## drhowarddrfine (Dec 17, 2018)

pyret That's a problem with your machine or installation, not Firefox. The millions of other users, including myself, have no such issues with it.


----------



## Deleted member 30996 (Dec 18, 2018)

pyret said:


> Browsers are one of the worst inventions of mankind. They keep getting more and more complex and slower and slower.
> *snip*
> JavaScript should be banned.



www/firefox used to have to option available to disable JavaScript back in the day. Now it's been removed from the Preferences options.

The uBlock Origin extension has the option to disable JavaScript. NoScript can be set to only allow scripts you choose to run. I use both and let NoScript handle the scripting. No scripts run on my machines unless I specifically allow it and no ads at all.

While I have had more problems with crashes with recent versions of www/firefox it's not been as bad lately. I do prefer www/firefox-esr but it's hard to tell any difference in using one from another.


----------



## sidetone (Dec 18, 2018)

I don't like Javascript, I like PHP, but Javascript has more capabilities, which in few cases is good.


pyret said:


> Browsers are one of the worst inventions of mankind. They keep getting more and more complex and slower and slower.


Then how else do you access the Internet effectively and FreeBSD forums?
Firefox had problems, but it's running smoothly for me now, unless a Javascript script runs in circles, which still, my browser doesn't crash.


----------



## Quarter Wave Vertical (Dec 18, 2018)

fraxamo said:


> I've been pushing Firefox hard for the last couple of hours and so far so good. Yesterday, I could hardly open more than a few tabs without it borking. Looks like this is fixed for me. Thanks again!


Same here.  After I made the aforementioned modification, Firefox has behaved itself.  So far, so good as they say....


----------



## drhowarddrfine (Dec 18, 2018)

pyret said:


> And that is on Windows 10


That explains everything and all you need to know but my wife has Windows 10 and Firefox and runs it without issue, too.


----------



## Quarter Wave Vertical (Dec 19, 2018)

Quarter Wave Vertical said:


> Same here.  After I made the aforementioned modification, Firefox has behaved itself.  So far, so good as they say....


It's now 2 days since I made the changes.  I've opened my regular web pages, played a number of YouTube videos, downloaded some archived MP3 files, and Firefox has remained stable without any crashes.

I must have done something right....


----------



## ronaldlees (Dec 21, 2018)

Quarter Wave Vertical said:


> If I have maybe 2 or 3 tabs open, however, it seems to play nice with me.



+1

It doesn't need to be a memory leak in the accurate sense, does it?  (I.E. never releasing for other programs).  It can just be a spendthrift (like I am in the hobby store).  When people use only a tab or two, the wallet still has some dough left in it.  I personally think browsers are crazy spend thrifts, which is ridiculous, but people want the "instant action"  experience that memory gives better than cache.   Actually, so do I - but only use a couple tabs usually - it seems prudent for security reasons if nothing else.

BTW:  I prefer a 5/8 wave.


----------

