GC root object types

更新时间:
复制 MD 格式

This document introduces the types of GC root objects, a key concept in Java memory management. A garbage collector identifies all live objects by starting from these roots and traversing their object references.

GC root objects

GC Roots are objects in specific regions from which the garbage collector starts scanning for live objects. For example, in the graph below, the garbage collector starts from the thread stack area, finds objects A and B, and then uses these two objects as starting points to scan for other objects.

image.png

Different areas hold different types of GC root objects, such as JNI Global, System Class, Thread, and Busy Monitor. In the GC root object list of a heap dump, you can view the object count, shallow size, and retained size for each root type.

GC root object types

Type

Description

Unknown

An unknown root type.

System Class

A java.lang.Class object loaded by the system class loader.

JNI Local

A JNI local reference.

JNI Global

A JNI global reference.

Thread Block

An object referenced from an active thread block.

Busy Monitor

An object used for thread synchronization, such as an object in a synchronized block or one involved in wait() or notify() calls.

Java Local

A local variable on a thread's stack frame.

Native Stack

An object passed as an argument to a native method.

Thread

A running java.lang.Thread object.

Finalizable

An object in the finalization queue, waiting for its finalize() method to be called.

Unfinalized

An object with a finalize() method that has not yet been queued for finalization.

Unreachable

An object unreachable from any GC root and therefore eligible for garbage collection.

stack frame

A frame on a thread's call stack that holds local variables.

nmethod

A method compiled to native code by the Just-In-Time (JIT) compiler.