Java stack and stack
1. The garbage collection mechanism only acts on the heap memory and has nothing to do with the stack memory;
2. stack: the access speed of the stack is faster than that of the stack, and the efficiency is high. Save the reference values of local variables and objects.
3. Heap: save large Variables
4. When the compiler processes int a = 3, it first creates a reference with the variable a in the stack, and then finds whether the value 3 exists in the stack. If the value does not exist, store 3;
This is also true when processing B = 3. Because 3 was previously stored, the compiler only needs to point the variable "create B" to 3 (which is helpful for space saving ).
In this case, both a and B point to 3 at the same time, but this does not affect their use. If a = 4 is defined again at this time, 4 needs to be stored in the memory, from a to 4, the modification of a value does not affect the value of B.
Memory Division: 1. registers. 2. Local method area. 3. Method area. 4. stack memory. Local variables are stored. And once the scope of the variable ends, the variable is automatically released. 5. heap memory. Storage is an array and an object (in fact, an array is an object). Every new object is created in the heap. Features: 1. Each object has a first address value. 2. Each variable in the heap memory has a default initialization value, which varies depending on the type. The integer is 0, decimal number 0.0 or 0.0f, boolean false char '\ u000000' 3, garbage collection mechanism.