01, the respective duties;
Stack memory is used to store local variables and method calls,
Heap memory is used to store objects in Java, whether it is a member variable, a local variable, or a class variable
The objects they point to are stored in heap memory.
02, exclusive or shared;
Stack memory belongs to a single thread, each thread will have a stack of memory, its stored objects
Only visible in the thread to which it belongs, that is, stack memory can be understood as private memory, and objects in heap memory
Visible to all threads, the objects in the team memory can be accessed by all threads
03, abnormal error;
If the stack memory does not have an available space storage method call and a variable, the JVM throws
Java.lang.StackOverFlowError.
If there is no space available in the heap memory to store the generated objects, the JVM throws
Java.lang.OutOfMemoryErroy
04, Memory;
Stack memory is much smaller than heap memory
Differences between heap and Stack in Java