WebExtensions Access to Low-level APIs

Dear gals & guys,

we have developed a Firefox extension, it works just fine, but after a prolonged use, there is a huge increase in RAM usage, since the extension is used for loading different web pages of our customers.

We have came up with the possible solution: calling the “doMMU()” function from the: “about:memory” address using the WebExtensions Websurf extension.

Is it possible this way? How can we access the low level API and the “Services.jsm”?

Command: “Cu.import(“resource://gre/modules/Services.jsm”);” does work only on: “about:memory” URL.

Thank you for helping us resolving the issue and making our extensions focused on a great user experience for our customers.

Regards
blueeye

It is not possible to do that from a WebExtension, and I doubt it ever will be.

Besides, does a memory minimization really help?

NilkasG, thank you for your reply.

The memory minimazation helps only a half way. From 1GB it gets shrinked to about 500MB.

Is there any way for extensions to enable pages not to consume so much memory, or to release the memory once the page is reloaded?

Thank you and have a nice day.

  • Depending on the amount of system memory, 1 GB is not that much. If your system isn’t low on memory, then don’t worry about it. If there is memory available, Firefox might just be using it for caches and stuff.

  • you say your add-on is “loading pages”. Which way exactly? Into tabs that you close afterwards?

The name of the addon is Websurf.cz

If you leave it surfing for 10 hours or 30 hours and more, the RAM gets stacked up.

If you would like to test it, you can use the username: “admin”.

So 1 GB is not that much? Some of our clients have 4GB RAM or so.

Thank you and have a nice day.

So I had your add-on running in a VM - first with 2GB RAM, then with 10GB, for about an hour each - circling through websites I didn’t understand, and Firefox (all processes together) never used more than 750MB, usually around 500MB. I didn’t notice any increase over time.

EDIT: Ok, 4 hours later, and Firefox is now using 900MB of the 10GB RAM …

Yes, that’s exactly the problem.

Why does Firefox RAM gets stacked up during the browsing websites?

I have also developed the plugin for Chrome and Opera and neither has this kind of problem.

Is there any way to fix this “memory leak”?

Thank you.

I think it is a known issue of Firefox to stack up memory over time, especially when closing a lot of tabs. I don’t have a specific issue to give you, but generally the way to fix it, is to report it on bugzilla.mozilla.org if it’s not reported yet with the appropriate tagging (I think memshrink or soemthing). In generally look for “memshrink”, it’s the effort of fixing memory issues with Firefox.

I started a test that I hoped to Give some answers:

VM

The VMs in the left column have 1500MB RAM, the ones in the center 1000MB, the ones on the right 700MB.
All are otherwise identical clones.
Directly after taking the screenshot above, I started your Websurf add-on.

It worked fine for at least 2 hours. All VMs were loading pages, and the memory usage of Firefox on the VMs with 1000 and 700MB RAM was still below 500MB, on the 1500MB VMs it was a bit higher.

Then I didn’t look at it for the next 6 or seven hours. When I came back, I was greeted by two rows of this:

The tabs are permanently in a loading state, completely unresponsive.
Your add-on is still doing it’s countdown thing and the browser UI is responsive.
The CPU usage is very low.

After talling firefox to “Stop It”, closing the tab and waiting for about 30sec I could start Websurf again (did it in one row only).
But not for long. The first one got such after just two or three page loads, the other two followed within minutes:

I’m not sure what to make of this …

1 Like

Thank you for such comprehensive answer.

We cannot find a way how to fix the memory leak.
Let’s hope Mozilla will fix this kind of problem, since we are not allowed to perform a doMMU() function within Services, low-level API.

Thank you.

I face the same problem of you -in fact it has been like this for so long, just found the same solution today. And also struck for the same reason :stuck_out_tongue:
I plan to use another process to track and do something at first but I cant come with the idea how to just free the memory without just simply kill Firefox.
I just come up with the most acceptable idea for me, to detect it then close/reopen the tabs.
It’s sad that the memory is leak and there’s no elegant workaround for the issue.

Hope you can post if you found the solution. Good luck.

FYI, I surf the web that use SPA (Single page application) style which is the way some websites these day tend to go too. Firefox cant survive this in a few minutes. Hope a lot of people complaint that Firefox die on these websites soon lol so they fix this issue.

Update* reopen method is not work, Firefox greedy faster than that so I just give up those site single page mechanic and force it to load new page (in the same tab) instead which consume much more network, from tracking network, Firefox load more content instead of ajax some content… but memory leak is not exists anymore (I even try change a page per sec).