Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Internet Explorer, why does memory leak stay, even when navigating away from pages?

The book Learning jQuery says IE has memory leak for the DOM object having a property referencing a function, and the function also referencing the DOM object, thus having a "circular reference", like this:

onload = function() {
    var foo = document.getElementById('foo');
    foo.onclick = function() {  // DOM object foo's onclick property refers to a function
       foo.innerHTML = "hello"  // the function's body refers to the DOM object
    }                           // therefore circular reference
}

IE can handle circular references for garbage collection, but not when the circular references involve both DOM object and Javascript object, because they are handled by different memory managers.

and:

[the memory leak... and] the resulting [reference] looping can't be released by IE even when we navigate away from the page.

never freed until browser is closed.

Is it true? Why does IE not release those memory even when a user leaves the page? Is it because the user may click Back and come back to the page, and IE would like to keep the state of the page? In that case, what if the user is on the memory leak page, and then clicks Back, and then goes to google.com? Then the page is not viewable by any Back or Forward, and the memory leak problem can go away without closing the browser?

Or even when the tab is closed, without closing the browser?

Does this kind of memory leak happen in IE 8 too?

like image 412
nonopolarity Avatar asked Jun 21 '10 08:06

nonopolarity


1 Answers

Memory leaks are a class of program bugs, so you're basically asking "why is IE buggy?". The answer to that is, obviously, "because a programmer, somewhere, made a mistake".

While some browsers intentionally keep the page state even when you navigate away from it (notably Opera and FF), a "memory leak" means memory that the program doesn't use anymore, but forgot to release. In this case, IE has stopped caring about that part of memory, but didn't tell this to the OS (Windows), which still sees it as "used by IE". So this part of the memory hangs in a no-man's land, until the browser is closed - because when the browser process exits, the OS marks all memory allocated to that process as "free".

Memory leaks are a rather insidious type of bug, because the program seems to function correctly, but gradually consumes more and more memory.

See e.g. http://en.wikipedia.org/wiki/Circular_reference and http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) for further reading on this topic.

like image 172
Piskvor left the building Avatar answered Sep 16 '22 17:09

Piskvor left the building