Performance optimizations for JavaScript (reasonable management memory)

Source: Internet
Author: User

By using a language that has a garbage collection mechanism, developers generally do not have to worry about memory management issues. However, the problem with JavaScript in memory management and collection is a bit different. One of the main problems is that the amount of available memory allocated to a Web browser is typically less than that allocated to a desktop application. The main purpose of this is to prevent the system from running out of all of the system memory and causing a crash of the Web page that runs JavaScript for security reasons. Memory throttling issues not only affect allocating memory to variables, but also affect the call stack and the number of statements that can be executed concurrently in one thread.

Therefore, make sure that you use the least amount of memory for better performance on your page. The best way to optimize memory consumption is to save only the necessary data for the code in execution. Once the data is no longer in use, it is best to release its reference by setting its value to null----This practice is called dereferencing. This practice applies to most global variables and properties of global objects. Local variables are automatically dereferenced when they leave the execution environment.

Eg:function Createperson (name) {

var localperson=new Object ();

Localperson.name=name;

return Localperson;

}

var Aa=createperson (June);

AA = null;//manual release of AA references

This pest for global variable AA requires that we manually dereference it when not using it.

However, releasing a reference to a value does not mean that the memory consumed by the value is automatically reclaimed. The real effect of dereferencing is to leave the value out of the execution environment so that it can be reclaimed the next time the garbage collector runs. This is today to understand the collation, hoping to help some friends.

Performance optimizations for JavaScript (reasonable management memory)

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.