• <small id='5TQE0'></small><noframes id='5TQE0'>

    <tfoot id='5TQE0'></tfoot><legend id='5TQE0'><style id='5TQE0'><dir id='5TQE0'><q id='5TQE0'></q></dir></style></legend>

          <bdo id='5TQE0'></bdo><ul id='5TQE0'></ul>

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

        Java 垃圾回收

        时间:2023-07-12

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

                <tbody id='5DmDS'></tbody>

              <small id='5DmDS'></small><noframes id='5DmDS'>

                  本文介绍了Java 垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Java 自动调用垃圾收集器,那为什么我们需要手动调用垃圾收集器呢?什么时候应该使用 System.gc()

                  Java automatically calls garbage collector, then why we need manual calls for garbage collection? When should use System.gc()

                  推荐答案

                  Java 自动调用垃圾收集器,那为什么我们需要手动调用垃圾收集器呢?

                  Java automatically calls garbage collector, then why we need manual calls for garbage collection?

                  我们不需要它们.实际上,在大多数情况下调用 System.gc() 对应用程序性能有害.请参阅我对 为什么会这样"的回答调用系统 gc 是一种不好的做法" 以获得详细说明.

                  We don't need them. Indeed, in most circumstances calling System.gc() is harmful for application performance. See my answer to "Why is it a bad practice to call system gc" for a detailed explanation.

                  什么时候应该使用 System.gc()

                  When should use System.gc()

                  如果应用程序知道它正在进入一个无事可做的阶段,并且用户不太可能注意到垃圾收集,那么也许可以调用 System.gc()以阻止用户将来遇到 GC 暂停.

                  If the application knows it is going into a phase where it has nothing else to do AND the user is unlikely to notice a garbage collection, then maybe it is OK call to System.gc() in an effort to stop the user experiencing GC pauses in the future.

                  缺点包括:

                  • 调用 System.gc() 通常会触发一次完整的 GC,这比新空间"的 GC 花费的时间要长得多.
                  • 用户实际上可能关心/注意到.例如,如果您在游戏中的关卡"之间调用 System.gc(),则加载下一个关卡需要更长的时间.
                  • 通过强制 GC,您会导致 JVM 使用额外的 CPU 周期等,这可能会干扰用户在其计算机上执行的其他事情.
                  • Calling System.gc() typically triggers a full GC which takes significantly longer than a GC of the 'new space'.
                  • The user may actually care / notice. For example, if you call System.gc() between "levels" in a game, you make loading the next level take longer.
                  • By forcing the GC, you are causing the JVM to use extra CPU cycles, etc which may potentially interfere with other things that the user is doing on his machine.

                  (在单元测试和系统调试期间调用 System.gc() 也可能有正当理由.)

                  (There can also be legitimate reasons to call System.gc() in unit tests, and during system debugging.)

                  这篇关于Java 垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Java不是垃圾收集内存 下一篇:java - 垃圾收集器如何快速知道哪些对象不再引用它们?

                  相关文章

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

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