JavaScript Memory leakage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.