JavaScript stacks and heap memory, scope

Source: Internet
Author: User

1. Stack stack "and heap":Simply put, the memory system allocated on the stack is automatically freed, the memory allocated on the heap is not released, and the memory is there even if the program exits. A stack is typically statically allocated memory, which is typically dynamically allocated on the heap. 2. Basic types and reference types:Basic type: A simple data segment stored in the stack memory.     The size of the data determines the amount of memory space that can be allocated. Reference type: An object stored in the heap memory, in which a pointer is actually saved, and the pointer points to another location.     Each space size is different, depending on the circumstances of the specific allocation. See the diagram of the Page60 page of JavaScript advanced programming for a clear understanding of the above two concepts. 3. Memory Variable storage space:This is the reason for the JS mechanism to survive. Only by understanding the allocation of this storage space can you better understand JS and write more efficient code. 4. Value passing and reference delivery issues:The value in the former memory does not change, and the value in the latter content changes. The parameters of function () {} functions in JS are interpreted as local variables, which are only useful in function. 5. Execution Environment (SCOPE)1. The execution environment determines the life cycle of the variable, and some code can access the variable's permissions.     This mechanism helps when memory is freed.     2. Sub-Global Execution Environment (window) and function execution environment. 3. The local environment of the function can access variables of the functional scope and have access to the variable 4 in the containing (parent) environment. The Global environment cannot access variables in the function environment. 6.JS is a language with an automatic garbage collection mechanismWe're not thinking about memory allocation and recycling issues, unlike C + +

JavaScript stacks and heap memory, scope

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.