7

Does anyone know how to initiate the garbage collection and memory reduction in Firefox (about:memory > Free memory > GC/CC/Minimize memory usage) from the terminal? This browser is using way to much RAM and I found that clicking on "Minimize memory usage" actually cuts the load by about 20-30%. Unfortunately, this doesn't last very long, but my idea is to create a Bash script and cron it.

7
  • Check this: support.mozilla.org/en-US/kb/… Note that an extension could be the one eating up memory. I limited the number of concurrent (content) Firefox processes in very old computers and memory issues stopped. Aug 9, 2020 at 23:11
  • 1
    Good question. It's frankly ridiculous these browsers don't manage their memory better by default.
    – Time4Tea
    Aug 10, 2020 at 10:51
  • @EduardoTrápani: Thx, unfortunately, it's the same with all extensions disabled and I already reduced the content process limit from 8 to 1...
    – david
    Aug 10, 2020 at 15:31
  • 1
    @Time4Tea: Yeah, right? Isn't this also a security issue? Also, what reason would a browser have to use that much resources apart from (voluntary or involuntary) "distributed computing applications"? It feels like I'm permanently donating basically half of my PCs computing power to the browser xo
    – david
    Aug 10, 2020 at 15:33
  • I run Firefox Nightly on a pretty old computer from 2008 and there are no memory issues. Could your expectations be wrong? I mean, the gap between the memory you think should be used and the one actually used? Do you experience memory issues? (since you are trying to manage memory directly). If you are running short on memory, swapping too much, etc, and you want to solve it you could ask a new question to see what happens to your particular Firefox instance. Please do state the browser's version and operating system. Aug 10, 2020 at 15:53

1 Answer 1

3

This can only be "automated" by opening a new tab and clicking the button which would be difficult to do but possible e.g. using xdotool or xvkbd, see:

https://askubuntu.com/questions/791793/how-can-i-automatically-open-an-url-in-firefox-and-click-on-a-specific-position

https://stackoverflow.com/questions/12026953/automatic-web-page-refresh-using-xdotool-not-sending-key-after-window-focus

If I were you, I'd instead use cgroups to limit Firefox RAM usage:

systemd-run --user -t -p MemoryMax=1500M firefox

This command works for me in Fedora 32.


Here's how you can run it from a shortcut:

cat firefox.desktop

[Desktop Entry]
Version=1.0
Type=Application
Name=Firefox RAM Limited
Exec=systemd-run --user -t -p MemoryMax=1500M firefox
Icon=firefox
Terminal=false
StartupNotify=false
16
  • 3
    Hi, the last option seems very interesting. Do I have to apply the systemd-run options to all Firefox "child processes" (e.g. WebExtensions and Web Content) or is it sufficient to limit the main process (firefox-bin)?
    – david
    Aug 10, 2020 at 15:35
  • Also, will this option take care if there are multiple instances (e.g. there are usually 2-3 instances of WebExtensions)? And is the syntax for systemd-run case-sensitive, i.e. will it still work if I do systemd-run --scope -p MemoryLimit=500M webextensions for WebExtensions? Thx a lot ^-^
    – david
    Aug 10, 2020 at 15:55
  • PS.: Btw, what would be the syntax to apply the options to multiple processes? Would this work: systemd-run --scope -p MemoryLimit=200M firefox-bin MemoryLimit=200 WebExtensions MemoryLimit=500M Web Content (and do I need to escape blank spaces)?
    – david
    Aug 10, 2020 at 16:09
  • 1
    Doing systemd-run --scope -p MemoryHigh=500M /opt/firefox/firefox opened a new Firefox window - is this setting permanent or do I have to open Firefox every time using the command?
    – david
    Aug 10, 2020 at 22:18
  • 1
    What happens if the process attempts to write to more memory than the limit? Does Firefox try to minimize its usage automatically or does it just crash?
    – bfrguci
    Jun 15, 2022 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .