Open Bug 1362767 Opened 7 years ago Updated 8 months ago

Firefox doesn't release memory after closing tabs

Categories

(Core :: General, defect)

54 Branch
x86_64
All
defect

Tracking

()

People

(Reporter: jeremy9856, Unassigned)

Details

(Keywords: memory-footprint, Whiteboard: [MemShrink:P3])

Attachments

(6 files)

User Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0
Build ID: 20170420084331

Steps to reproduce:

Hello,

Firefox doesn't release memory after closing some tabs. The Web Content process release the memory only when you open an empty tab and close all the other one. I tried in safe mode but it's the same.

I'm on Fedora 25, Firefox 53.

Here is my user.js

user_pref("layers.acceleration.force-enabled", true);
user_pref("browser.tabs.remote.autostart", true);
user_pref("browser.tabs.remote.force-enable", true);
user_pref("extensions.pocket.enabled", false);
user_pref("privacy.trackingprotection.enabled", true);
user_pref("browser.safebrowsing.enabled", false);
user_pref("browser.safebrowsing.malware.enabled", false);
user_pref("dom.event.clipboardevents.enabled", true);
user_pref("browser.tabs.loadBookmarksInBackground", true);
user_pref("reader.parse-on-load.enabled", false);
user_pref("plugins.navigator_hide_disabled_flash", true);

Thanks !
Attached file memory-report.json.gz
memory not released
memory released
Component: Untriaged → Tabbed Browser
Keywords: footprint
OS: Unspecified → Linux
It's quite important because you run out of memory (4Gb) after a day of work and need to close all tabs (or Firefox).
Severity: normal → critical
Priority: -- → P1
jeremy9856: Please do not fiddle with the Priority value when you are not involved in doing the actual work. Thanks.
Severity: critical → normal
Priority: P1 → --
It's really not clear this bug is anything to do with the tabbrowser itself, moving back for triage.
Component: Tabbed Browser → Untriaged
Hello,
I was able to reproduce this release memory issue with 20170522030207 build, running on Windows 10 Pro, x64.
Steps to reproduce:
1. Launch mozilla nightly build.
2. Make sure that you have at least three tabs opened (used in test: http://cnn.com, http://www.eurosport.com/, http://www.bbc.com).
3. Open Task Manager.
4. Observe memory usage when closing first tab and second one.

Expected results:
Release memory is reflected in Task Manager.

Actual results:
Memory usage keeps increasing before is stabilized.
Maybe someone with more experience regarding the process of memory cleaning could provide more feedback for this issue.

Kind regards,
Alin
Status: UNCONFIRMED → NEW
Component: Untriaged → Memory Allocator
Ever confirmed: true
OS: Linux → All
Product: Firefox → Core
Hardware: Unspecified → x86_64
Whiteboard: [MemShrink]
Version: 53 Branch → 54 Branch
Moving to Core::Untriaged -- I suspect this needs further investigation before pinning it as a problem specific to the memory allocator?
Component: Memory Allocator → Untriaged
(In reply to jeremy9856 from comment #0)
> User Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101
> Firefox/53.0
> Build ID: 20170420084331
> 
> Steps to reproduce:
> 
> Hello,
> 
> Firefox doesn't release memory after closing some tabs. The Web Content
> process release the memory only when you open an empty tab and close all the
> other one. I tried in safe mode but it's the same.

This is expected behavior, the web content process will stay open with e10s enabled. The only way to force close it is with the method you noted.

Please note that in newer versions we have "e10s-multi" which means you can have up to 4 web content processes. If you have for tabs open I would expect for web content processes, if you close 3 of those I would expect 1-2 web content processes to remain.

So to clarify, is the problem that when you closed a few tabs memory didn't go down? The best way to measure that is to take a memory report with the tabs open, close the tabs, *wait a few minutes*, measure again. I'd expect the memory to go down, if it does not you can try the 'minimize memory usage' button in about:memory and measure again. If the results are not satisfactory can you upload those memory reports?

Another note: from your memory report it looks like a fair amount is allocated for images:

> 642.28 MB (100.0%) -- explicit
> ├──487.16 MB (75.85%) -- images
> │  ├──486.58 MB (75.76%) -- content
> │  │  ├──485.39 MB (75.57%) -- raster/used
> │  │  │  ├──267.54 MB (41.65%) -- image(1302x802, <anonymized-1>)
> │  │  │  │  ├──260.33 MB (40.53%) -- locked
> │  │  │  │  │  ├──256.34 MB (39.91%) ── surface(1302x802 (animation))/decoded-heap
> │  │  │  │  │  └────3.98 MB (00.62%) ── surface(1302x802, compositing frame)/decoded-heap
> │  │  │  │  └────7.21 MB (01.12%) ── source
> │  │  │  ├──189.64 MB (29.53%) -- image(2640x1408, <anonymized-6>)
> │  │  │  │  ├──186.80 MB (29.08%) -- locked
> │  │  │  │  │  ├──172.62 MB (26.88%) ── surface(2640x1408 (animation))/decoded-heap
> │  │  │  │  │  └───14.18 MB (02.21%) ── surface(2640x1408, compositing frame)/decoded-heap
> │  │  │  │  └────2.84 MB (00.44%) ── source
> │  │  │  ├───24.26 MB (03.78%) -- image(582x256, <anonymized-14>)
> │  │  │  │   ├──22.13 MB (03.45%) -- locked
> │  │  │  │   │  ├──21.56 MB (03.36%) ── surface(582x256 (animation))/decoded-heap
> │  │  │  │   │  └───0.57 MB (00.09%) ── surface(582x256, compositing frame)/decoded-heap
> │  │  │  │   └───2.13 MB (00.33%) ── source
> │  │  │  └────3.96 MB (00.62%) ++ (12 tiny)
> │  │  └────1.19 MB (00.19%) ++ vector/used
> │  └────0.58 MB (00.09%) ++ (2 tiny)

It's possible we have a leak there, but the odds are you're on a website that's rendering a few large images, which is also expected behavior.
Flags: needinfo?(jeremy9856)
(In reply to Eric Rahm [:erahm] (please no mozreview requests) from comment #10)
> So to clarify, is the problem that when you closed a few tabs memory didn't
> go down? 

Yes. When you close a tab the memory used by this tab should be freed. That not the case even after minutes or hours, because, like I said in comment 3, I run out of memory (4Gb) after a day of work and need to close all tabs (or Firefox) to get back my memory ! I will upload some memory reports when I will have the time but you should see it by yourself just by opening a lot a tabs and closing them except one.

> Another note: from your memory report it looks like a fair amount is
> allocated for images.
> It's possible we have a leak there, but the odds are you're on a website
> that's rendering a few large images, which is also expected behavior.

I don't remember what site I browsed. I will make some tests if I have time.
Flags: needinfo?(jeremy9856)
Whiteboard: [MemShrink] → [MemShrink:P3]
Flags: needinfo?(jeremy9856)
Whiteboard: [MemShrink:P3] → [MemShrink:P3][closeme 2017-08-15]
Flags: needinfo?(jeremy9856)
Here is 4 logs. 

1. I opened something like 20 tabs (without a lot of images, mostly archwiki) and made memory-report-before.json.gz

2. I closed most of the tabs (leave something like 4 opened) and made memory-report-just-after.json.gz

3. I waited 15mn without using Firefox and made memory-report-15mn-after.json.gz

4. I used a little bit Firefox for 1h without opening new tabs and made memory-report-1h-after.json.gz

Hope it help :)
Comparing #1 with #3 the memory usage goes down after closing the tabs, I'm not sure what the issue is at this point. The amount would be larger but there's a fair amount in bin-unused; this is expected and is memory that will be reused when you open more tabs.
You are right, in #3 the memory goes down but not enough. In Gnome system monitor Firefox took about 350Mb and Web Content about 600Mb with all tabs opened. In #3 still in Gnome system monitor Firefox took about 350Mb and Web Content 400Mb with only 4 tabs remaining open. So I repeat, the problem is, after a day of use the unreleased memory pile up and Firefox consume far too much memory.
Whiteboard: [MemShrink:P3][closeme 2017-08-15] → [MemShrink:P3]
Moving from Core::Untriaged to Core::General https://bugzilla.mozilla.org/show_bug.cgi?id=1407598
Component: Untriaged → General

Firefox doesn't release the memory back to the OS. This can lead to thrashing and useless writes to virtual memory. I have to restart firefox every once in a while. Some webapps can use Gigs of RAM, without releasing that memory back to the OS it means some time later unused memory will be written to disk which will cause unexpected jitter throughout the OS and increases potential for thrashing.

benzakhar: You need to provide proof and clear steps to reproduce for statements.

I'm sorry I bring no new information, these are the steps that also reproduce for me as mentioned above.

  1. Open htop to observe memory used by firefox
  2. Open a couple tabs that consumes memory
  3. close the tabs
  4. observe on htop that a significant amount of memory is still held by firefox
  5. restart firefox and notice that firefox has a way less memory footprint.

I didn't know about:memory. I'm going to try those buttons next time instead of restarting firefox. Sorry I brought no new information that the people above have given, just frustrated as recently I needing to restart firefox quite a bit.

Glad to help diagnose this bug, please let me know what data I can provide.

Issue still present in Firefox five years after initial bug was cut, has been persistent all these years with no discernible improvement across any of the 12+ devices I've used, multiple OS (Linux, MacOS, Windows).

An example from today on Ubuntu 20.04 with Firefox 100.0.2, 32 GB RAM. After closing dozens of tabs so I only have 6 tabs left open, Firefox memory usage stayed at ~12 GB as though I closed no tabs. Using the buttons in about:memory to initiate GC and such has only minor effect, decreasing memory usage to ~4 GB. As other posters mention, the only fix that reliably works is closing Firefox and reopening, at which point memory usage for the exact same 6 open tabs fell from ~11 GB to ~4 GB!

The site which most reliably triggers this issue for me is Amazon.

(In reply to holocronweaver from comment #23)

Woops, typo fixed below. Should have been 11 GB, not 4 GB.

Using the buttons in about:memory to initiate GC and such has only minor effect, decreasing memory usage to ~11 GB.

Severity: normal → S3

I confirm the same issue on 116 on Windows.
After some time of opening / closing several tabs, memory usage remains permanently elevated, even if I go back to the original tabs I had open.

Using "minimize energy usage" in about:memory does reduce memory usage a bit, but it never recovers to the level used by the original tabs.
It remains fairly high.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: