This topic contains the following sections.
Internet Explorer 8 includes improvements to memory management that mitigate memory leaks previously created by circular references between Microsoft JScript objects and Document Object Model (DOM) objects.
This feature may affect the behavior of Web pages that depend on garbage memory that existed in previous versions of Internet Explorer only as the result of a memory leak. In Internet Explorer 8, these pages reference unallocated memory and generate a fault.
This feature affects each Web site displayed in Internet Explorer 8 regardless of the site's chosen compatibility mode.
As described in detail in Understanding and Solving Internet Explorer Leak Patterns, the JScript garbage collector in previous versions of Internet Explorer manages the lifetime of JScript objects but not of DOM objects. As a result, the JScript garbage collector cannot break circular references between DOM objects and JScript objects, and memory leaks occur. In Microsoft Internet Explorer 6, these circular references are broken when the Internet Explorer process terminates. In Internet Explorer 7, these circular references are broken when users navigate away from the page that contains the leaks.
In Internet Explorer 8, the JScript garbage collector treats DOM objects referenced by JScript objects as JScript objects. Rather than wait until page navigation as in Internet Explorer 7 or process termination as in Internet Explorer 6, the garbage collector manages the lifetime of these DOM objects and breaks circular references whenever possible throughout the lifetime of the site.
Although Web developers should be aware of memory leaks created by use of programming patterns such as JScript closures in Internet Explorer 7 and earlier, those patterns no longer result in leaks in Internet Explorer 8.
This section contains simplified examples of code patterns that would previously result in memory leaks but do not leak in Internet Explorer 8.
function leaktest1()
{
var elem1 = document.createElement("DIV");
elem1.thing = elem1;
}
function leaktest2()
{
var elem1 = document.createElement("DIV");
var elem2 = document.createElement("DIV");
elem1.thing = elem2;
elem2.item = elem1;
}
function leaktest3()
{
var x = new Object();
x.obj = document.createElement("DIV");
x.obj.jsobj = x;
}
function leaktest4()
{
var elem1 = document.createElement("DIV");
document.body.appendChild(elem1);
elem1.thing = elem1;
elem1.parentElement.innerHTML = "";
}
function leaktest5()
{
var elem = document.createElement("DIV");
elem.onload = function (){
var y = elem;
}
}
function leaktest6(){
var elem = document.createElement("DIV");
document.body.appendChild(elem);
elem.onload = function () {
var y = elem;
}
elem.removeNode();
}
function leaktest7()
{
var elem = document.createElement("DIV");
document.body.appendChild(elem);
elem.onload = function () {
var y = elem;
}
elem.parentElement.innerHTML = "";
}
function leaktest8()
{
var elem = document.createElement("DIV");
elem.thing = elem.setAttribute;
}