卸载样式表时 Mozilla 中的内存泄漏
我正在受限设备(摩托罗拉机顶盒)上使用 Mozilla v1.7.12,试图解决一些内存泄漏问题。
当我动态加载引用一些大图像的样式表时,我可以看到消耗的内存量随着图像的大小而增加。这是我所期望的。
然后,当我从 DOM 中删除样式表时,我希望释放内存。然而,这并没有发生。
这是一个问题,因为我正在开发的 Web 应用程序需要能够在页面的生命周期中多次动态加载和卸载样式表。
因此,我的问题是:我所看到的行为是预期的行为还是已知的错误?有办法解决这个问题吗?
我应该指出,我已将样式表中所有图像的过期标头设置为 -1。
[更新]
如果我不断加载和卸载样式表,浏览器会消耗越来越多的内存。因此,浏览器似乎不会重用相同的内存。
I'm working with Mozilla v1.7.12 on a constrained device (a Motorola set-top box) trying to resolve some memory leaks.
When I dynamically load a stylesheet which refers to some large images, I can see that the amount of consumed memory increases in correspondance with the size of the images. This is what I would expect.
Then, when I remove the stylesheet from the DOM, I would expect the memory to be freed. However, this does not happen.
This is a problem, because the web application I'm working on needs to be able to dynamically load and and unload stylesheets potentially many times in the lifetime of the page.
My question therefore is this: Is what I'm seeing expected behavior or is it a known bug? Is there a way to work around this?
I should point out that I've set the expires header to -1 on all the images in the stylesheet.
[Update]
If I keep loading and unloading stylesheets, the browser consumes more and more memory. Therfore, it seems not to be the case that the browser reuses the same memory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否是一个错误是一个非常主观的问题。浏览器在需要时使用内存,最多在认为不再需要时放弃。它可能永远不会释放内存,因为保留它以供重用比不断放弃和请求它更有效。
简而言之,再次猜测任何程序为什么或何时消耗和释放内存通常是徒劳的(当然,除非这是您的代码)。
您是否尝试过一个接一个地加载多个样式表?您可能会发现,即使浏览器没有返回内存,它也会重用同一个池,因此总内存使用量实际上并没有增加。
Whether it's a bug or not is a very subjective question. The browser uses memory when it needs it, and at best relinquishes when it doesn't think it needs it any more. It may never release the memory because it's more efficient to hold onto it for reuse than to keep relinquishing and requesting it.
In short, second guessing why or when any program consumes and releases memory or not is often a hopeless endeavor (unless it's your code of course).
Have you tried to load several stylesheets, one after the other? You might find that even though the browser hasn't returned the memory, it reuses the same pool, so that the total memory usage doesn't actually grow.