• <small id='rAlqS'></small><noframes id='rAlqS'>

    <tfoot id='rAlqS'></tfoot>

      <i id='rAlqS'><tr id='rAlqS'><dt id='rAlqS'><q id='rAlqS'><span id='rAlqS'><b id='rAlqS'><form id='rAlqS'><ins id='rAlqS'></ins><ul id='rAlqS'></ul><sub id='rAlqS'></sub></form><legend id='rAlqS'></legend><bdo id='rAlqS'><pre id='rAlqS'><center id='rAlqS'></center></pre></bdo></b><th id='rAlqS'></th></span></q></dt></tr></i><div id='rAlqS'><tfoot id='rAlqS'></tfoot><dl id='rAlqS'><fieldset id='rAlqS'></fieldset></dl></div>
        <bdo id='rAlqS'></bdo><ul id='rAlqS'></ul>

    1. <legend id='rAlqS'><style id='rAlqS'><dir id='rAlqS'><q id='rAlqS'></q></dir></style></legend>

        什么是类的 GC 根?

        时间:2023-07-12

        <small id='fddHl'></small><noframes id='fddHl'>

          <tfoot id='fddHl'></tfoot>
        1. <legend id='fddHl'><style id='fddHl'><dir id='fddHl'><q id='fddHl'></q></dir></style></legend>

            • <bdo id='fddHl'></bdo><ul id='fddHl'></ul>
                <tbody id='fddHl'></tbody>

                <i id='fddHl'><tr id='fddHl'><dt id='fddHl'><q id='fddHl'><span id='fddHl'><b id='fddHl'><form id='fddHl'><ins id='fddHl'></ins><ul id='fddHl'></ul><sub id='fddHl'></sub></form><legend id='fddHl'></legend><bdo id='fddHl'><pre id='fddHl'><center id='fddHl'></center></pre></bdo></b><th id='fddHl'></th></span></q></dt></tr></i><div id='fddHl'><tfoot id='fddHl'></tfoot><dl id='fddHl'><fieldset id='fddHl'></fieldset></dl></div>

                  本文介绍了什么是类的 GC 根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 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 root:

                  This article describes four types of GC roots:

                  • 局部变量
                  • 活跃的话题
                  • 静态变量
                  • JNI 参考

                  还提到:

                  类本身可以被垃圾回收.

                  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.

                  如果没有任何东西可以到达类加载器——这意味着没有任何东西可以到达由该类加载器创建的任何类或这些类的任何实例——那么类加载器和它创建的类都可以进行垃圾回收.在此之前保持它们处于活动状态是必要的,以便 Class::forName 和 ClassLoader::findClass 即使在类的静态初始化器不是时也可以是幂等的.

                  If there is nothing which can reach a classloader - which means nothing can reach any classes created by that classloader or any instances of those classes - then both the classloader and the classes it created are eligible for garbage collection. Keeping them alive until then is necessary so that Class::forName and ClassLoader::findClass can be idempotent even when the class's static initializers are not.

                  隐藏类(参见 https://openjdk.java.net/jeps/371)是该规则的例外.作为 OpenJDK 的一个实现细节,使用 java.lang.reflect.Proxy 的静态方法创建的方法引用、lambda 和代理类也是如此.类加载器不持有对这些类的强引用.

                  Hidden classes (see https://openjdk.java.net/jeps/371) are exceptions to this rule. As an implementation detail of OpenJDK, so are the classes of method references, lambdas, and proxies created with the static methods of java.lang.reflect.Proxy. The classloader does not hold a strong reference to these classes.

                  这篇关于什么是类的 GC 根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何禁用 Java 垃圾收集器? 下一篇:system.gc() 和 runtime.gc() 之间的区别

                  相关文章

                  <small id='kuodJ'></small><noframes id='kuodJ'>

                      <tfoot id='kuodJ'></tfoot>
                        <bdo id='kuodJ'></bdo><ul id='kuodJ'></ul>
                    1. <legend id='kuodJ'><style id='kuodJ'><dir id='kuodJ'><q id='kuodJ'></q></dir></style></legend>
                    2. <i id='kuodJ'><tr id='kuodJ'><dt id='kuodJ'><q id='kuodJ'><span id='kuodJ'><b id='kuodJ'><form id='kuodJ'><ins id='kuodJ'></ins><ul id='kuodJ'></ul><sub id='kuodJ'></sub></form><legend id='kuodJ'></legend><bdo id='kuodJ'><pre id='kuodJ'><center id='kuodJ'></center></pre></bdo></b><th id='kuodJ'></th></span></q></dt></tr></i><div id='kuodJ'><tfoot id='kuodJ'></tfoot><dl id='kuodJ'><fieldset id='kuodJ'></fieldset></dl></div>