Java stack constant pool and java constant pool
JavaHeap(Each object contains the corresponding class information, and the [class information is stored in the method area]), and the memory allocated in the heap, there is a virtual machine's automatic garbage collector management, stack memory is only visible to its thread.
JavaStackSave some basic data types (int, long, byte, double, float, char, boolean, short) and reference variables. The heap memory is visible to all threads.
Error
IfStack memoryNo available space storage method calls and local variables, JVM will throw java. lang. StackOverFlowError.
If yesHeap memoryNo available storage space for the generated objects, JVM will throw java. lang. OutOfMemoryError.
Space size
The stack memory is much smaller than the heap memory. If you use recursion, your stack will soon be full. StackOverFlowError may occur if recursion does not jump out in time.
You can use the-Xss option to set the stack memory size. -The Xms option can be used to set the size at the beginning of the heap, and the-Xmx option can be used to set the maximum value of the heap.
Method Area:
It is also called a static zone, which is shared by all threads like a heap. It is used to store data such as class information, constants, static variables, and compiled code that has been loaded by virtual machines.