从此IBM article on handling memory leaks in Java :
The garbage collector starts at the root nodes, classes that persist throughout the life of a Java application, and sweeps through all of the nodes that are referenced. As it traverses the nodes, it keeps track of which objects are actively being referenced. Any classes that are no longer being referenced are then eligible to be garbage collected. The memory resources used by these objects can be returned to the Java virtual machine (JVM) when the objects are deleted.
在 Java 应用程序的生命周期中持续存在的类有哪些?
最佳答案
您所问的也称为垃圾收集根。来自 Yourkit's documentation of GC roots :
There are several kinds of GC roots. One object can belong to more than one kind of root. The root kinds are:
Class - class loaded by system class loader. Such classes can never be unloaded. They can hold objects via static fields. Please note that classes loaded by custom class loaders are not roots, unless corresponding instances of java.lang.Class happen to be roots of other kind(s).
Thread - live thread
Stack Local - local variable or parameter of Java method
JNI Local - local variable or parameter of JNI method
JNI Global - global JNI reference
Monitor Used - objects used as a monitor for synchronization
Held by JVM - objects held from garbage collection by JVM for its purposes. Actually the list of such objects depends on JVM implementation. Possible known cases are: the system class loader, a few important exception classes which the JVM knows about, a few pre-allocated objects for exception handling, and custom class loaders when they are in the process of loading classes. Unfortunately, JVM provides absolutely no additional detail for such objects. Thus it is up to the analyst to decide to which case a certain "Held by JVM" belongs.
您也可以从 The Truth About Garbage Collection 阅读(已注明日期)。
关于java - 了解 Java 中的内存泄漏。在 Java 应用程序的整个生命周期中持续存在的类有哪些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12242904/