views:

28

answers:

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.

A: 

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.

Marcelo Cantos
Thanks for the suggestion. Unfortunately, what I'm observing is that the browser keeps consuming more memory when I unload and load more stylesheets.
KaptajnKold
Another guess, then, is that the browser keeps the CSS around until the page is reloaded and thus a new DOM created.
Marcelo Cantos