heap
Objects are stored in the heap
There is only one heap area in the jvm, which is shared by each thread
Advantages and disadvantages: the memory is dynamic, the life cycle is uncertain, and the GC is automatically recycled, and the speed is slow
stack
The stack stores basic data types and references to custom objects (non-objects)
Each thread has a stack area, the data in the stack is private, and the thread is exclusive
The stack is divided into three parts: basic type variables, execution environment context, operation instruction area
Advantages and disadvantages: fast, but fixed size and life cycle, inflexible
method area
Also called static area, shared by all threads
Store all classes, static variables
Contains elements that are always unique in the entire program, such as: class, static variables
direct memory
Off-heap memory, not part of the virtual machine data area, can be allocated, the size is limited by the native memory
Compared with the heap area, the IO read and write performance is better than the heap area, and frequent applications are more expensive.