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