<bdo id='G2JZs'></bdo><ul id='G2JZs'></ul>

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

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

    2. 对象何时有资格进行垃圾收集?

      When Is The Object Eligible For Garbage Collection?(对象何时有资格进行垃圾收集?)

        • <bdo id='LMCuq'></bdo><ul id='LMCuq'></ul>

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

            <tfoot id='LMCuq'></tfoot>
              <tbody id='LMCuq'></tbody>

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

              1. 本文介绍了对象何时有资格进行垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在下面的代码中,假设 amethod 已被调用.myObject 最初引用的对象在哪一点/哪一行符合垃圾回收条件?

                In the code below, given that amethod has been called. At what point/line is the Object originally referenced by myObject, eligible for Garbage Collection?

                class Test {
                  private Object classObject;
                
                  public void amethod() {
                    Object myObject = new Object();
                    classObject = myObject;
                    myObject = null;
                  }
                }
                

                如果 classObjectamethod 具有 public、protected、default 或 static 的访问修饰符,它会影响对象符合垃圾收集条件的点吗?如果有,会受到怎样的影响?

                And if classObject or amethod had an access modifier of public, protected, default or static, would it affect what point the Object is eligible for Garbage Collection? If so, how would it be affected?

                • 我的第一个想法是,当 Test 对象符合垃圾回收条件时,该对象符合垃圾回收条件.
                • 但话又说回来了.优化器可能知道 classObject 永远不会被读取,在这种情况下 classObject = myObject; 将被优化出来并且 myObject = null; 是它有资格进行垃圾收集的点.
                • My first thought is that the Object is eligible for Garbage Collection when the Test object is eligible for Garbage Collection.
                • But then again. The optimizer may know that the classObject is never read from in which case classObject = myObject; would be optimized out and myObject = null; is the point it is eligible for Garbage Collection.

                推荐答案

                对象将不会成为垃圾回收的候选对象,直到对它的所有引用都被丢弃.Java 对象是通过引用分配的,所以当你有

                The object will not become a candidate for garbage collection until all references to it are discarded. Java objects are assigned by reference so when you had

                   classObject = myObject;
                

                您为堆上的同一对象分配了另一个引用.所以这一行

                You assigned another reference to the same object on the heap. So this line

                   myObject = null;
                

                只去掉一个引用.要使 myObject 成为垃圾回收的候选对象,您必须拥有

                Only gets rid of one reference. To make myObject a candidate for garbage collection, you have to have

                  classObject = null;
                

                这篇关于对象何时有资格进行垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

              2. <tfoot id='yjhP1'></tfoot>

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

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

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