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

        <legend id='673UT'><style id='673UT'><dir id='673UT'><q id='673UT'></q></dir></style></legend>
      1. <small id='673UT'></small><noframes id='673UT'>

        <tfoot id='673UT'></tfoot>

        • <bdo id='673UT'></bdo><ul id='673UT'></ul>

      2. 实习生字符串、字符串池和 perm-space 上的垃圾收集

        时间:2023-07-12

        <small id='2wMx8'></small><noframes id='2wMx8'>

          <tfoot id='2wMx8'></tfoot>
            <legend id='2wMx8'><style id='2wMx8'><dir id='2wMx8'><q id='2wMx8'></q></dir></style></legend>

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

                • 本文介绍了实习生字符串、字符串池和 perm-space 上的垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在探索了 java 的字符串内部结构后,我对所谓的perm 空间"感到困惑.我最初对它的理解是它包含 String literals 以及类元数据,如 这个问题.

                  After exploring java's string internals I've grown confused on what is referred to as the "perm space." My understanding initially of it was that it held String literals as well as class meta data as explained in this question.

                  我还阅读了有关 String.intern() 方法的信息,它会将 String 放入字符串池中,返回对其唯一实例的引用.据我了解,这是保存在 JVM 永久空间中的字符串文字的同一个字符串池.在我看来,烫发空间"似乎不可能是可修改的(毕竟它是永久的,是吗?).但后来我发现 this question 其中 EJP 对已接受的最高投票评论答案说明了

                  I've also read about the String.intern() method and that it places Strings into the String Pool returning a reference to unique instance of it. It is my understanding that this is the same string pool holding String literals that exists in the JVM's perm-space. It didn't seem possible to me that the "perm-space" could be modifiable, (it is permanent after all, yes?). But Then I found this question where the top voted comment by EJP on the accepted answer explains that

                  Intern'd 字符串已经支持 GC 好几年了.

                  Intern'd strings have been GC-able for quite some years now.

                  暗示 GC 在 perm-space 上运行,这似乎不是很永久.这如何调和?GC 会检查 perm-space 中的所有内容吗?GC 是否检查字符串池中的所有内容,包括来自源的字符串文字?实习生字符串是否有第二个字符串池?GC 是否只知道在收集时查看实习生字符串?或者这个评论是错误的并且实习一个字符串会阻止它被 GC(我希望不是这种情况)?

                  Implying that the GC runs on the perm-space which doesn't seem very permanent. How does this reconcile? Does the GC check everything in the perm-space? Does the GC check everything in the string pool including string literals from the source? Is there a second string pool for intern'd strings? Does the GC know only to look over intern'd strings when collecting? Or is this comment mistaken and intern'ing a string prevents it from ever being GC'd (which I hope is not the case)?

                  推荐答案

                  字符串字面量 被实习.从 Java 7 开始,HotSpot JVM 将实习字符串在堆中,而不是 permgen.

                  String literals are interned. As of Java 7, the HotSpot JVM puts interned Strings in the heap, not permgen.

                  在 java 7 之前,热点将实习字符串放在 permgen 中.但是,permgen 中的实习字符串被垃圾回收了.显然,permgen 中的类对象也是可收集的,所以一切in permgen 是可收集的,尽管在某些旧 JVM 中默认情况下可能不会启用 permgen 收集.

                  Prior to java 7, hotspot put interned Strings in permgen. However, interned Strings in permgen were garbage collected. Apparently, Class objects in permgen are also collectable, so everything in permgen is collectable, though permgen collection might not be enabled by default in some old JVMs.

                  被实习的字符串字面量将是声明类对象持有的对实习池中字符串对象的引用.因此,只有当引用它的 Class 对象也被收集时,才会收集实习字面量 String.

                  String literals, being interned, would be a reference held by the declaring Class object to the String object in the intern pool. So the interned literal String would only be collected if the Class object that referred to it were also collected.

                  这篇关于实习生字符串、字符串池和 perm-space 上的垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么不调用finalize? 下一篇:你如何从 Shell 强制垃圾收集?

                  相关文章

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

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

                      <small id='4A6Qx'></small><noframes id='4A6Qx'>