views:

42

answers:

2

Hello,

I have a very basic ajax slideshow on my website. On every scroll, the new images and response content continually increase the amount of memory used by the browser.

I've done my research and tried all suggestions to reset the XHR object on each new request, but this does absolutely nothing to help.

The slideshows are basic but may contain hundreds of slides. I want a user to be able to navigate the slideshow indefinitely without crashing their browser. Is this even possible?

Thanks, Brian

A: 

If its a slideshow, are you only showing one image at a time? If you do only show one at a time and you're never getting rid of the last one you show, it will always increase the memory. If you remove the slides not being shown, it should help.

Justin
Currently I'm simply replacing the HTML contents via innerHTML, so I'm not sure if that counts as officially removing it. Would formally deleting the DOM node with javascript do what you are describing?
Brian
I don't think you need to free the XHR object, it won't save much memory. In fact, try to use the same one in all calls.What seems to be consuming memory here is the growing amount of content you're showing for each page. You should try to keep only 3 at a time: t-1, t, t+1. Replacing old content with new via innerHTML should delete the old resources in theory -- make sure you're not accidentally storing them in a string variable or in another reference. I'd try placing the content exchange in a function with limited scope, so that every time the function is exited, the memory will be freed.
Cahit
+1  A: 

Increasing memory usage is normal. You are, after all, loading more data each time - the HTML from your AJAX response, as well as the images that are being displayed. Unless you're using Adobe Pagemill-generated HTML, that's only going to be a few hundreds of bytes of HTML/text. It's the images that will suck up the most space. Everything get stuffed into the browser's cache.

Since you're not doing anything fancy with the DOM (building sub-trees and whatnot) directly, just replacing a chunk of HTML repetitively, eventually the browser will do a cleanup and chuck some of the unused/old/stale image data from memory/cache and reclaim some of that memory.

Now, if you were doing some highly complex DOM manipulations and generating lots of new nodes on the fly, and were leaking some nodes here and there, THEN you'd have a memory problem, as those leaked nodes will eventually bury the browser.

But, just increasing memory usage by loading images is nothing to worry about, it's just like a normal extended surfing session, except you're just loading some new pictures.

Marc B
Incredibly helpful, thank you.
Brian