1. <small id='L2WaD'></small><noframes id='L2WaD'>

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

      <tfoot id='L2WaD'></tfoot>

      Java 垃圾收集如何与循环引用一起使用?

      How does Java Garbage Collection work with Circular References?(Java 垃圾收集如何与循环引用一起使用?)

      1. <small id='QufL5'></small><noframes id='QufL5'>

        <tfoot id='QufL5'></tfoot>

              <tbody id='QufL5'></tbody>
              <bdo id='QufL5'></bdo><ul id='QufL5'></ul>
              <legend id='QufL5'><style id='QufL5'><dir id='QufL5'><q id='QufL5'></q></dir></style></legend>

                <i id='QufL5'><tr id='QufL5'><dt id='QufL5'><q id='QufL5'><span id='QufL5'><b id='QufL5'><form id='QufL5'><ins id='QufL5'></ins><ul id='QufL5'></ul><sub id='QufL5'></sub></form><legend id='QufL5'></legend><bdo id='QufL5'><pre id='QufL5'><center id='QufL5'></center></pre></bdo></b><th id='QufL5'></th></span></q></dt></tr></i><div id='QufL5'><tfoot id='QufL5'></tfoot><dl id='QufL5'><fieldset id='QufL5'></fieldset></dl></div>
              • 本文介绍了Java 垃圾收集如何与循环引用一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                据我了解,Java 中的垃圾回收会清理一些对象,如果没有其他对象指向"该对象.

                From my understanding, garbage collection in Java cleans up some objects if nothing else is 'pointing' to that object.

                我的问题是,如果我们有这样的事情会发生什么:

                My question is, what happens if we have something like this:

                class Node {
                    public object value;
                    public Node next;
                    public Node(object o, Node n) { value = 0; next = n;}
                }
                
                //...some code
                {
                    Node a = new Node("a", null), 
                         b = new Node("b", a), 
                         c = new Node("c", b);
                    a.next = c;
                } //end of scope
                //...other code
                

                abc 应该被垃圾回收,但它们都被其他对象引用.

                a, b, and c should be garbage collected, but they are all being referenced by other objects.

                Java 垃圾收集如何处理这个问题?(或者仅仅是内存消耗?)

                How does the Java garbage collection deal with this? (or is it simply a memory drain?)

                推荐答案

                如果无法通过从垃圾收集根开始的链访问对象,Java 的 GC 会将其视为垃圾",因此将收集这些对象.即使对象可能相互指向形成一个循环,但如果从根部切断它们仍然是垃圾.

                Java's GC considers objects "garbage" if they aren't reachable through a chain starting at a garbage collection root, so these objects will be collected. Even though objects may point to each other to form a cycle, they're still garbage if they're cut off from the root.

                请参阅 Java 平台中的附录 A:垃圾收集的真相中关于不可访问对象的部分性能:战略和战术 用于血淋淋的细节.

                See the section on unreachable objects in Appendix A: The Truth About Garbage Collection in Java Platform Performance: Strategies and Tactics for the gory details.

                这篇关于Java 垃圾收集如何与循环引用一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                Java System Environment Variable(Java 系统环境变量)
                Java -classpath option(Java -classpath 选项)
                Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                Issue with JAVA_HOME(JAVA_HOME 的问题)

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

                          <bdo id='czh6r'></bdo><ul id='czh6r'></ul>
                        • <small id='czh6r'></small><noframes id='czh6r'>