1. Original information
1.1 title
JavaScript Memory Leaks
1.2 website
[Http://nesj.net/blog/2012/04/javascript-memory-leaks/]
2 JavaScript Memory leakage
2.1 What is memory leakage
Memory leakage is defined as: the system allocates memory for the application, but it cannot be re-allocated even if the memory is no longer used. Generally, the garbage collector collects DOM elements and event handles when they are no longer referenced or unavailable. However, memory leakage is inevitable for earlier IE browser versions (IE7 or earlier), because the memory manager does not handle the javascript Memory lifecycle well, and the memory will not be declared again until the memory loop is forcibly broken by a value of null.
2.2 why do you need to pay attention to memory leaks?
Memory leakage is usually caused by internal programming errors in large web applications. When the wasted memory exceeds the maximum memory size that the system can provide, the performance of web applications will be greatly reduced. As a web application developer, developing a web application to meet functional requirements is only the first step. The performance requirements are equally important to the completion of basic functions of web applications. Otherwise, this will increase the possibility of potential failure and cause the browser to crash.
2.3 In javascript, what is the main cause of Memory leakage?
2.3.1 loop reference
A simple example is a DOM object referenced by a javascript object, and the same or another javascript Object is being applied at the same time. This DOM object may cause memory leakage. Although the script has stopped running, reference to this DOM element will not be reclaimed by the garbage collector. This mode usually occurs in a series of object references and it is very difficult to detect whether the current object still has references. To interrupt the circular reference, either point the javascript Object to the DOM object or assign the DOM object to null.
2.3.2 javascript Closure
Because of the limitations of javascript scopes, many features are implemented by using javascript closures. If you want to know