Next: Garbage collector
Java memory management: garbage collection and allocation
Overview
The memory management component of the Java runtime environment is composed of...
Allocator Allocates space for objects in a contiguous section of memory called the heap. Garbage collector Frees up space in the heap when an object is no longer needed.
Heap
The heap is a contiguous section of virtual memory where all the Java objects in a running JVM are stored. The maximum size of the Java heap is preallocated when the JVM starts.
Another memory area that Java uses is the system (or native) heap where allocations from application JNI code, compiled JIT code, and threads to map to Java threads, among other things are stored. The Java heap is commonly referred to as "the heap."
Allocator
All running threads have a local allocation buffer (cache). The cache block for all threads is sometimes called the thread local heap (TLH). Objects are allocated from the TLH if possible; if this is not possible, then a locked heap allocation is performed. If many allocations occur at once, then heap lock can become an issue. GC policies try to avoid heap lock through unique allocation algorithms.