I have an AJAX-based website using JavaScript on the client. Certain operations on the site cache large result sets from service calls in the browser (i.e. hundreds of megabytes). These are throw-away results. They will be viewed for a short time and then need to be cleared from memory.
I've written a small test site that loads a bunch of junk in memory and then calls JavaScript's delete
method. This works great in Firefox (memory almost instantly gets returned). Internet Explorer 8 (haven't tried 7) doesn't free the memory until the page is refreshed or closed.
Does anyone know how to drop IE's memory usage using JavaScript/Ajax (no page refreshes)?
Below is my sample client code:
function load() {
var x = ['dfjasdlfkjsa;dflkjsad;flkjsadf;lj'];
for( var i = 0; i < 10000000; ++i ) {
x.push('asdfasfasfsfasdfkasjfslafkjslfjsalfjsaldfkjasl;dfkjsadfl;kjsdflskajflskfjslakfjaslfkjsaldfkjsaldfksdfjk');
}
alert('deleting'); // <--- memory usage around 500mb
delete x; // <--- immediate results in Firefox 3.5 (not IE8)
alert('done');
}
UPDATE: Setting the variable to 'null' does not immediately clear the memory (as that is left up to the garbage collector). Also, setting a variable null only gets a single reference where there might be multiple references.