课程的GC根源是什么? [英] What are GC roots for classes?
问题描述
在Java中,有一些名为垃圾收集根(GC根)的特殊对象。它们作为垃圾收集标记机制的根对象(见图)。
In Java, there are special objects called Garbage Collection Roots (GC roots). They serve as a root objects for Garbage Collection marking mechanism (see picture).
本文描述了四种类型的GC根:
This article describes four types of GC roots:
- 本地变量
- 活动线程
- 静态变量
- JNI参考
- local variables
- active threads
- static variables
- JNI references
还提到, :
类本身可以被垃圾收集。
Classes themselves can be garbage-collected.
不收集GC根,因此类本身不是GC根。
GC roots aren't collected thus classes themselves are not GC roots.
那么类的GC根源是什么?
So what are GC roots for the classes?
推荐答案
那么类的GC根源是什么?
So what are GC roots for the classes?
类加载器,有效 - 通过其他GC根源。
Classloaders, effectively - via other GC roots.
如果没有任何东西可以到达类加载器 - 这意味着没有任何东西可以到达该类加载器创建的类的任何实例 - 那么类加载器和它创建的类都有资格进行垃圾回收。
If there is nothing which can reach a classloader - which means nothing can reach any instances of classes created by that classloader - then both the classloader and the classes it created are eligible for garbage collection.
这篇关于课程的GC根源是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!