Circular Reference
function SetupLeak()
{
myGlobalObject = document.getElementById("LeakedDiv");
document.getElementById("LeakedDiv").expandoProperty = myGlobalObject;
}
{
myGlobalObject = document.getElementById("LeakedDiv");
document.getElementById("LeakedDiv").expandoProperty = myGlobalObject;
}
That is, Dom element holds the reference to the jscript scope object.
Closure
function AttachEvents(element)
{
element.attachEvent("onclick", ClickEventHandler);
function ClickEventHandler() { // This closure refs element}
}
function SetupLeak()
{
// The leak happens all at once
AttachEvents(document.getElementById("LeakedDiv"));
}
That is, Element holds reference to closure, but at the same time, the closure holds reference to the parent function's parameter.
{
element.attachEvent("onclick", ClickEventHandler);
function ClickEventHandler() { // This closure refs element}
}
function SetupLeak()
{
// The leak happens all at once
AttachEvents(document.getElementById("LeakedDiv"));
}
That is, Element holds reference to closure, but at the same time, the closure holds reference to the parent function's parameter.
Cross-Page Leaks
DOM Insertion Order Lead.
If we insert elements from parent to child, Thn No Memory Leak:
parentElement.appendChild(childElement);
childElement.appendChild(subChildElement);
But if we use it this way, Memory Leak will Happen:
childElement.appendChild(subChildElement);
parentElement.appendChild(childElement);
Pseudo-Leaks



被折叠的 条评论
为什么被折叠?



