. Stacks in Java:
such as Student Student = new Student ();
Here the object is the new student, the object is stored in the heap memory, and student is the reference to this object as follows
In general, Java programs run with several storage areas as follows:
Program Counter:
Can be seen as the line number indicator of the currently executing byte code. Usually it is changing the value of the counter bytecode to choose the next code to execute, the programmer does not directly control.
Register:
We have no direct control in the program and are managed by the compiler.
Stack area:
1, each thread contains a stack that holds only objects of the underlying data type and references to custom objects and local variables.
2, the data in each stack is private and cannot be accessed by other stacks.
3, when the local data is exhausted, the occupied memory space is automatically released.
One of the greatest uses of the JVM stack is to perform a Java method service, where each method is executed to create a stack frame for storing local variable tables, operations stacks, dynamic links, method exits, and so on.
Each method from the invocation until the completion of the process corresponds to a stack frame in the virtual machine from the stack to the stack process.
The advantage of the stack is that the access speed is faster than the register. The disadvantage is that the size and life cycle of the data stored in the stack is deterministic and lacks flexibility.
Heap Area:
1, arrays and objects created by new are stored in the heap.
2, each object has a corresponding memory address value.
3, the variables in the object have default initialization values.
4, arrays and objects become garbage when no reference variable points to it, can no longer be used, but still occupy memory, which is released by the garbage collector at a later indeterminate time.
It is also clear that each Java application uniquely corresponds to a single JVM instance, with each instance uniquely corresponding to a heap. The Java heap must also contain address information that can be found for object type data (such as Object type, parent class, implemented interface, method, and so on).
These types of data (precedence over the existence of objects) are stored in the method area.
The advantage of a heap is that it can dynamically allocate the size of memory, and the life cycle does not have to tell the compiler beforehand because it allocates memory dynamically at runtime and reclaims unused data with a garbage collection mechanism. The disadvantage is that the access speed is relatively slow.
Objects are typically accessed through a reference to an object. Pending additions and modifications
Data structure of objects in Java (to be supplemented)