- It is very important to understand the memory area where objects, variables, etc. in Java are stored
- This article will comprehensively explain the memory model & partitioning in the Java virtual machine. I hope you will like it
Directory
##1. Memory Model & Partition
When the Java virtual machine runs a Java program, it will manage a memory area: the runtime data area
In the runtime data area, it will be divided according to usage:
- Java virtual machine stack (stack area)
## Below, I will introduce each memory model partition in detail
2. Java堆
3. Java虚拟机栈
4. 本地方法栈
Introduction: Very similar to the Java virtual machine stack, but different from the Java virtual machine It lies in: the service object, that is, the Java virtual machine stack serves to execute Java methods; the local method stack serves to execute Native methods
5. 方法区
6. 程序计数器
7. 额外知识:直接内存
- Definition: The channel- and buffer-based I/O method in the NIO class (introduced in JDK1.4) uses the Native function library Directly allocated off-heap memory
- Features: Not limited by heap size
Does not belong to virtual machine runtime data Part of the area & not allocated in the heap
- Application scenario: Suitable for scenarios with frequent calls
Operate through a DirectByteBuffer object stored in the Java heap as a reference to this memory, thereby avoiding copying data back and forth between the Java heap and the Native heap and improving performance
- Exception thrown: OutOfMemoryError, that is, the sum of other memory areas is greater than the physical memory limit
8. Summary
This article comprehensively explains the memory model & partitioning in JVM, summarized as follows
The above is the detailed content of 13 Diagrams Illustrating the Memory Model in Java. For more information, please follow other related articles on the PHP Chinese website!