How to judge whether an object is alive in jvm
Determine whether it is reachable: need to have a dependency with the root node
If there is no reference to my gc roots, then gc considers it to be unreachable
The basic idea of the root search algorithm is to search downward from these nodes through a series of objects named "GC Roots". The path of the search is called reference chain (Reference Chain). When an object is not connected to the GC Roots, it is proved that the object is unavailable.
In the Java language, objects that can be used as GCRoots include the following:
(1)。 The object referenced in the virtual machine stack (the local variable area in the stack frame, also known as the local variable table).
(2)。 The object referenced by the static property of the class in the method area.
(3)。 An object referenced by a constant in the method area.
(4)。 The object referenced by the JNI (Native method) in the local method stack.