Java run-time memory allocation
A Java process can contain multiple threads
A Java process corresponds to a unique JVM instance
A JVM instance uniquely corresponds to a heap
Each thread has a private stack of its own
You can also see the heap of threads sharing processes, but not the stack
This article has a thread and a process surface question.
Heap
The heap is shared by threads
A process with only one heap
The heap holds the object itself and the array itself
In Java, arrays (such as int[]) also inherit object objects, not inheritance object[]
Stack
Data structure inside said, stack is first into the back out
The stack holds references to objects (declarations and reference objects are sequential and may also be related to stacks)
Heap and Stack comparisons
Stack is faster than heap, heap allocation is more flexible than stack
Generally, the available heap space is larger than the stack
Static Storage Area
There seems to be an objection to this, does Java have any static storage area?
Usually with static
keywords stored in the static storage area
Don't dig into the details.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Runtime memory allocation heap and stack differences