Exploring the different generations on the heap
The heap space consists of two different memory areas:
- Young generation space
- Old generation (tenured) space.
While we will not dive into the GC process in this chapter, we need to explain what a live object is. A live object is one that is reachable from the GC roots.
Garbage collection roots
A GC root is a special type of live object and is, therefore, not eligible for GC. All objects reachable from GC roots are also live and are, therefore, not eligible for GC. The GC roots act as starting points in GC, that is, start at these roots and mark all objects reachable as live. The most common GC roots are the following:
- Local variables on the stack
- All active Java threads
- Static variables (as these can be referenced by their classes)
- Java Native Interface (JNI) references – Objects created by the native code as part of a JNI call. This is a very special case of GC roots because the JVM...