What is a memory leak
A memory leak is a piece of allocated memory that is neither available nor recyclable until the browser process finishes. In C + +, memory leaks are a frequent occurrence because of the manual memory management. And now popular in C # and Java and other languages using automatic garbage collection method to manage memory, normal use of the case almost no memory leaks. Memory is also managed by the automatic garbage collection method in the browser, but a memory leak can occur because of a bug in the browser garbage collection method.
Memory Leaks Quick View
There are a variety of memory leaks in different browsers, and the main findings are currently:
1. Circular Reference
Browsers that have confirmed a leak: IE6.0 FF2.0
Circular references with DOM objects cause most of the current mainstream browser memory leaks here are two simple concepts
Reference: A. Attribute =b,a the reference to B
Circular reference: In short, if a refers to b,b and references A,a and B, it forms a circular reference.
A and B circular references:
var a=new Object;
var b=new Object;
a.r=b;
b.r=a;
A Loop quote yourself:
var a=new Object;
a.r=a;
Circular references are common and are harmless in most cases, but circular references cause memory leaks when there are DOM objects or ActiveX objects in the object that participates in the circular reference. If we replace any of the new object in the example with document.getElementById or document.createelement, a memory leak will occur.
Although this may seem very easy to understand, it is difficult to detect because of the closure involvement that complicates things, and some closure lead to circular references. The following is a very common dynamic binding event:
function bindEvent()
{
var obj=document.createElement("XXX");
obj.onclick=function(){
//Even if it's a empty function
}
}