EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

Circular Memory Leak Mitigation

Windows Internet Explorer 8 improvements in memory management.

This topic contains the following sections.

Overview

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.

Compatability: Changes in Behavior from Internet Explorer 7

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.

Feature Details

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.

Code Samples

This section contains simplified examples of code patterns that would previously result in memory leaks but do not leak in Internet Explorer 8.

Direct Circular Memory References

  • Circular reference with DOM object referring to itself where the object is not in the tree

function leaktest1() 
{
    var elem1 = document.createElement("DIV");
    elem1.thing = elem1;
}

  • Circular reference between DOM objects not in the tree

function leaktest2() 
{
    var elem1 = document.createElement("DIV");
    var elem2 = document.createElement("DIV");
    elem1.thing = elem2;
    elem2.item = elem1;
}

  • Circular reference between a DOM object and a JScript object

function leaktest3() 
{
    var x = new Object();
    x.obj = document.createElement("DIV");
    x.obj.jsobj = x;
}

  • Circular reference between DOM object referring to itself when removed from the tree using innerHTML

function leaktest4()
{
    var elem1 = document.createElement("DIV");
    document.body.appendChild(elem1);
    elem1.thing = elem1;
    elem1.parentElement.innerHTML = "";
}

Circular Memory References Created by Closures

  • Closure with element created dynamically

function leaktest5() 
{
    var elem = document.createElement("DIV");
    elem.onload = function (){
    var y = elem;
    }
}

  • Closure with element added to tree and removed using removeNode

function leaktest6(){
    var elem = document.createElement("DIV");
    document.body.appendChild(elem);
    elem.onload = function () {
    var y = elem;
    }
    elem.removeNode();
}

  • Closure with element added to tree and removed using innerHTML

function leaktest7() 
{
    var elem = document.createElement("DIV");
    document.body.appendChild(elem);
    elem.onload = function () {
    var y = elem;
    }
    elem.parentElement.innerHTML = "";
}

  • Leaks caused by function pointers

function leaktest8() 
{
    var elem = document.createElement("DIV");
    elem.thing = elem.setAttribute;
}

커뮤니티 추가 항목

표시:
© 2014 Microsoft