Talking about JavaScript performance-managing memory

Source: Internet
Author: User

Last time I said, where should JavaScript scripts be placed? What's the use?

The following 2 points:

    1. In the HTML, the body part of the JS will be loaded on the page when the execution. That is-the script executed when the user triggers an event. Eg:onload Events ...
    2. The JS in the HTML, head section is executed when it is called . That is-often used to generate the contents of a page.

In summary: Place the JavaScript identity

A lot of ink, always want to pour out a brain. Calm down the mood and ideas, or think, slowly to Bai ...

Performance chapter-Managing Memory

First, a little white, when it comes to memory, this is about heap memory. Say what is heap memory? By the way, it should be explained in a moment, first of all, the computer's memory allocation:

One, memory allocation method

1, global variables and static variables (static variables) are automatically allocated and freed by the compiler, the initialized global variables and static variables are placed in the same memory area, the uninitialized global variables and static variables are placed in another contiguous memory area.

2, Stack, is automatically allocated and released by the compiler, mainly the address of the function body, parameters and local variables, static variables are not contained therein, the operation is similar to the stack in the data structure.

3, heap, is manually completed by the programmer application and release, such as malloc and new, the programmer did not manually release, when the program at the end of the system freed from the free space, and its implementation is completely different from the heap in the data structure, the way the heap is implemented in some similar to the data structure of the linked list.

4, program code area, for storing the program's binary code space.

5, text constant area, like a constant string, etc. stored here, the program is released after the end of the system.

In the form of a heap of memory presented or allocated in a way called heap memory (self-expression, do not like to spray)

The Chrome browser's V8 engine is majestic and powerful. All JavaScript objects in V8 are allocated by the "heap" for memory allocation, and when we declare variables, V8 allocates a portion of the heap memory to the variable, and if not enough, continue to ask for heap memory, so that V8 will continue to allocate memory until the memory limit is reached. Popularity, V8 heap memory size limit, 64-bit operating system is 1464MB, about 1.4GB, and then 32-bit operating system is the upper limit of 732MB, about 0.7GB. It's a shame!

When it comes to the point, manage memory-dereference → applies to most global variables and properties of global objects, and local variables are automatically dereferenced when they leave the execution environment.

It's better to say so much than to cite an example, eg:

function CREATP (name) {  var localp = new Object ();  Localp.name = name;  return localp;          }  var Globalp = createp ("Nick");  Manual de-globalp reference  Globalp = null;

Note: 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.

By the way, a variable of the JS base data type holds the actual value of the base data type, whereas a variable of the reference type holds a reference to it, the pointer.

Basic data Type (Sbunn): String, Boolean, Undefined, number, Null;

Reference data type (FOA): Function, Object, Array

Talking about JavaScript performance-managing memory

Related Article

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.