How to force Firefox (Version 6) to free memory?
Asked Answered
V

2

5

I'm working on a slide-show-like web app in which the current image is drawn onto a canvas and you can flip through images with next/prev buttons. The images a loaded with someImage.src and for performance reasons I'm doing that in background while user views first image. Firefox allocates lots of memory during that preloading (up to 20-30 times more than Chrome or Safari do and even twice as much as IE). Moreover, if I change the slide show, which I can do via loading an xml description of the slide show in background (with a drop down menu) while the URL of the web site remains the same, no memory is freed, but a lot new is allocated. Not until I change or reload the URL of the web site Firefox deallocs the memory. This behavior is different to all other browsers.

What's going on there? Why is Firefox so hungry? Any ideas, how to fix that? Is there a way to force Firefox to free memory or to reduce the memory it uses for pre-caching loaded (but not shown) images?

Varicolored answered 23/8, 2011 at 9:48 Comment(3)
This isn't a constructive comment, but I gave up long ago believing in Firefox's ability to handle memory with care. Firefox 7 beta is supposed to have improved the situation thoughSoerabaja
JavaScript's garbage collector is never directly callable as far as I know, so I think you're out of luck.Renowned
@Gregory: might not be constructive, but it's always good to hear, that you're not the only one, isn't it?Varicolored
A
6

Even if it looks sometimes that firefox allocates more and more memory, that might be deceptive. Firefox garbage collector works somewhat strange (to me). Its not unusual that it takes 2-8 minutes before Firefox decides to free a huge chunk of memory. Probably worth a look into the source code.

However, you might be able to speed up things by nulling some of your variables/references so the garbage collector has a chance to detect a little earlier as to what it should abandon. That is especially a good idea with canvas elements/references. So, easily setting not more used/needed variables

myCanvasRef = null;

should do some work for you. If you still think that Firefox uses too much memory, open a new tab and type in about:memory. That'll give you a detailed view from the current browser memory usage. For instance, you can see if that memory is used for Javascript code, Images or other stuff which is very useful to confine the bad guys.

Amerind answered 23/8, 2011 at 9:55 Comment(3)
What about the delete statement? (I'd imagine that null, undefined and delete all work equally as they decrease the object's reference count.)Errand
I would be careful about delete especially when thinking about other browsers (of course, especially IE). I don't think there is a differece between null and undefined tho.Amerind
null and undefined are used interchangeably for the same purpose, but null is always an object, and undefined is always a primitive.Errand
M
1

If you came here looking for "how to force GC in firefox" one way is navigate to about:memory then click the "gc" button.

Unfortunately that didn't seem to help much in my particular case, but in case it's useful to followers there is it. link

Miscarriage answered 12/5, 2016 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.