JavaScript variable types Save locations and references in memory

Source: Internet
Author: User

1. JavaScript variables

  The base type value occupies a fixed amount of space in memory and is therefore stored in the stack memory.

Copying the underlying values from one variable to another will create this worth a copy.

The value of a reference type is that the object is saved in heap memory.

The containing reference type the worthy variable actually contains not the object itself but a pointer to that object.

Copying the value of a reference type from one variable to another is actually a pointer, so two variables end up pointing to the same object

2. Heap and Stack

  The meaning of a stack in a data structure is the way a group of numbers are stored in LIFO

  Push: Add data at the top level

Pop: Returns and removes the topmost data

Top: Returns the value of the topmost data without removing it

IsEmpty: Returns a Boolean value that represents the current stack is empty stack

A Stack is an area of memory that holds data   . The system divides two different memory spaces stack (stack) and heap (heap)

Stacks are structured (like LIFO, bottom-up) and each region is stored in a certain order, and the size of each chunk can be clearly known. Heap is no structure data can be stored arbitrarily. Therefore, the stack is addressed faster than the heap.

In general, each thread allocates one stack (stack) per process to allocate a heap. That is, the stack is an exclusive thread and the heap is a shared thread.

so   local stack heap inside local variable Once run end recycling and Span style= "Font-family:consolas;" >heap GC Span style= "font-family: the song Body;" > The memory here is recycled. Therefore general memory leaks are Fangsheng in .

  Use the stack like we go to a restaurant to eat, just order (send application), pay, and eat (use), eat enough to go, do not bother to cut vegetables, wash vegetables and other preparation work and washing dishes, brush pots and other finishing work, the follow-up work of these dishes seems to be garbage collection without our own hands. His advantage is quick, but the freedom is small.

using the heap is like making your own favorite dishes, more troublesome, but more in line with their own tastes, But we're going to have to clean up these things ourselves and wash the dishes . and a great degree of freedom .

JavaScript variable types Save locations and references in 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.