admin管理员组文章数量:1399329
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?
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?
Share Improve this question asked Aug 23, 2011 at 9:48 Kai HuppmannKai Huppmann 10.8k7 gold badges51 silver badges80 bronze badges 3- 1 This isn't a constructive ment, 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 though – Gregory Pakosz Commented Aug 23, 2011 at 9:51
- JavaScript's garbage collector is never directly callable as far as I know, so I think you're out of luck. – pimvdb Commented Aug 23, 2011 at 9:56
- @Gregory: might not be constructive, but it's always good to hear, that you're not the only one, isn't it? – Kai Huppmann Commented Aug 23, 2011 at 10:04
2 Answers
Reset to default 6Even 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 null
ing 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.
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
本文标签: javascriptHow to force Firefox (Version 6) to free memoryStack Overflow
版权声明:本文标题:javascript - How to force Firefox (Version 6) to free memory? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744204450a2595118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论