ev8
ev8

Reputation: 83

Removing iframe contents from memory onunload/onbeforeunload in IE7

I have an iframe which is loaded into my page through ajax. On every interval a new iframe overwrites the old one. For some reason the iframe content stays in my memory in IE7. I'm sure its the iframe content because when I load a small site into the iframe, the memory size raises slowly. When I load a large site into the frame it goes way faster with each refresh.

I would like to clear the iframe content from the memory everytime the interval is called. I tried the scripts below (this one is for window.onunload - I also tried this every interval) but both don't work and keep the iframe content in my memory until I end the browser session.

// Remove iframecontents
window.onunload = function() {
    $('iframe').each(function(i, frame) {
        frameDoc = frame.contentDocument || frame.contentWindow.document;
        frameDoc.removeChild(frameDoc.documentElement);
    });
}

// Remove iframe with jQuery
window.onunload = function() {
    $('iframe').each(function(i, frame) {
        $(frame).remove();
    });
}

If there any way to remove the contents from the iframe from my memory without having to restart the browser?

These solutions don't seem to work either: Iframes and memory management in Javascript jQuery DOMWindow script doesn't release memory

Upvotes: 4

Views: 1326

Answers (1)

cakidnyc
cakidnyc

Reputation: 489

My experience with IE since Windows 7 has always been that you can't explicitly force it to garbage collect. It works together with Windows dynamic memory management. If your system is overall low on memory, then IE will start to release memory more often. If you have a lot of available memory, it will hold on until you kill the process.

However, it is true that each page (or iframe) does suck up a certain amount of memory and IE tends to unload a big chunk of it only when you navigate away. This is a bad situation for SPA apps (single page applications). It makes it even more important to code wisely to keep memory usage low in the first place.

Upvotes: 1

Related Questions