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

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

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

        如何在 Java 中释放内存?

        时间:2023-07-13
          <bdo id='67vgD'></bdo><ul id='67vgD'></ul>
          <tfoot id='67vgD'></tfoot>

                <small id='67vgD'></small><noframes id='67vgD'>

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

                  本文介绍了如何在 Java 中释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法在 Java 中释放内存,类似于 C 的 free() 函数?还是将对象设置为 null 并依赖 GC 是唯一的选择?

                  Is there a way to free memory in Java, similar to C's free() function? Or is setting the object to null and relying on GC the only option?

                  推荐答案

                  Java 使用托管内存,因此分配内存的唯一方法是使用 new 运算符,并且唯一的方法是释放内存依赖于垃圾收集器.

                  Java uses managed memory, so the only way you can allocate memory is by using the new operator, and the only way you can deallocate memory is by relying on the garbage collector.

                  本内存管理白皮书 (PDF) 可能帮助解释发生了什么.

                  This memory management whitepaper (PDF) may help explain what's going on.

                  您也可以调用 System.gc() 来建议垃圾收集器立即运行.但是,Java 运行时做出最终决定,而不是您的代码.

                  You can also call System.gc() to suggest that the garbage collector run immediately. However, the Java Runtime makes the final decision, not your code.

                  根据 Java 文档,

                  调用 gc 方法表明Java 虚拟机花费精力朝着回收未使用的对象为了让他们的记忆目前占用可用于快速重用.当控制权从方法调用,Java 虚拟机已尽最大努力收回所有丢弃的对象的空间.

                  Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.

                  这篇关于如何在 Java 中释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Java 线程垃圾是否收集 下一篇:什么时候在java中对字符串进行垃圾收集

                  相关文章

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

                    <tfoot id='yoKom'></tfoot>
                  1. <small id='yoKom'></small><noframes id='yoKom'>

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