views:

19

answers:

1

Hi

I am running into a memory issue with webkit browsers on Windows with my current project. I will first describe the project I work on, then describe the actual issue. Please take my apologies for the long text, I hope it's not too much..

I am working on a project that lets you view a printed magazine online. For iPad support it is done in HTML/CSS/JS (Mootools), not in Flash. Basically it shows a double-page at a time, loading new ones via JSON. That double-page is basically a div containing an image and potentially some extra elements. When a double-page is out of view, it's container-div is removed from the DOM after all images are "unloaded" by setting their 'src' to a 1px white jpg, and also I try to null out and delete all properties on the div before it'sremoved from the DOM.

Firefox, Opera and IE do the unloading properly, and I can see that the RAM usage stays about the same, no matter how many pages I view - new pages are loaded in, old ones are loaded out. Or at least you see that from time to time memory is freed up to the normal value, probably by garbage collection.

Safari and Chrome on the other hand don't free up any memory at all and memory usage rises with each new viewed page. So the RAM is filled up more and more, probably until there's none available anymore. When you go back and view already-loaded pages, memory usage stays the same.

Now, I thought the memory is used to cache the loaded images in some way, but I figured out that when you disable styles from within the developer menu of Safari, the RAM usage always drops to the same "normal" value, no matter what it was was previously. This means: If you view a number of pages, and Safari fills up say 500MB of RAM, and you disable styles, RAM usage drops to ~120MB. Now if you view even more pages, and let Safari occupy say over 1GB of RAM, and you disable the styles, again the RAM usage drops to about 120MB.

Thus, I conclude that the RAM is not used up by image data, but by style-related data of some kind. ANd this is wizardry or vodoo to me: I really don't know how to approach the problem from here on. I am having difficulties to research the problem, and maybe I didn't even identify it yet.

Maybe somebody here can bump me into a proper direction?

here is a link to a dev-version of the project: http://loopmodefiles.com/mindpirates/mag/

Thanks

A: 

Hmm. I kind of doubt it's really deliberately-kept style data... I would suspect it's just that WebKit's memory cache is being lazy about discarding resources, and needs something to kick it into action. Switching stylesheets would be something that would leave a bunch of background images now-unused so I guess they're using that as a trigger for memory cache cleanup. There may be other triggers.

I'm not sure what WebKit's memory cache heuristics are, but it wouldn't surprise me if resources like images loaded by a page were kept in memory cache indefinitely, at least as long as there was ample working memory.

bobince