Introduction to Memory Pools
A memory pool is a section of memory that is used for making specific kinds of allocations. Understanding memory pools is important because it helps us deal with performance problems or application failures due to memory issues. Also, knowing whether the JVM manages a particular memory pool or not determines the approach and the tools that can be used to troubleshoot issues related to that memory pool.
Memory Pools Used by Java Applications
There are four memory pools that Java applications have access to and can allocate from: the Java Heap, Metaspace, CodeCache, and native memory.
The Java Heap is where Java objects are allocated. Metaspace is where classes and their metadata are stored. CodeCache is where the just-in-time compilers store the compiled code.
Lastly, native memory can be used by both the JVM and the native code of applications. Poonam Parhar has described the complexity of native memory allocations, noting that the JVM can perform “allocations for internal structures, loaded jars and native libraries, thread stacks, and so on. Additionally, Java applications can have JNI or JVMTI code making allocations from native memory. NIO and Direct ByteBuffer also make native memory allocations. The fact that native allocations can come from several different places makes it very hard to detect and diagnose native memory related problems.”
Native Memory Tracking (NMT)
Native Memory Tracking (NMT) is a Java HotSpot VM feature that tracks
internal memory usage for a Java HotSpot VM. You can access NMT data by
using the jcmd utility. It is a useful tool for detecing memory leaks
and monitoring VM internal memory.
Please see the NMT documentation for your version of the JDK To learn how to use NMT:
- JDK 25 (LTS)
- JDK 21 (LTS)
- JDK 17 (LTS)
- JDK 11 (LTS)
- JDK 8 (LTS):
Monitoring memory consumption with JConsole
JConsole can be used to monitor consumption of memory pools. Please see the JConsole documentation for your version of the JDK for more information:
See also
- Troubleshooting Native Memory Leaks in Java Applications
- Understanding the Java Heap Versus the Native (C) Heap
- Interface MemoryPoolMXBean documentation
Last reviewed on Sat Feb 01 2025 00:00:00 GMT+0000 (Coordinated Universal Time)