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

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

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

      1. <tfoot id='5Pah5'></tfoot>
        <legend id='5Pah5'><style id='5Pah5'><dir id='5Pah5'><q id='5Pah5'></q></dir></style></legend>

      2. Java 的垃圾收集何时释放内存分配?

        时间:2023-07-12
        <legend id='0MGJb'><style id='0MGJb'><dir id='0MGJb'><q id='0MGJb'></q></dir></style></legend>

          <tbody id='0MGJb'></tbody>

            <tfoot id='0MGJb'></tfoot>

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

                • <bdo id='0MGJb'></bdo><ul id='0MGJb'></ul>

                  <small id='0MGJb'></small><noframes id='0MGJb'>

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

                  问题描述

                  我在 Java 中创建了一个名为 FOO 的对象.FOO 包含大量数据.. 我不知道说我已经拉入 ram 进行操作的 10 兆字节文本文件.(这只是一个例子)

                  I have created an object in Java, Named FOO. FOO contains a large amount of data.. I don't know say for a ten mega byte text file that I have pulled into ram for manipulation.(This is just an example)

                  这显然是一个巨大的空间,我想从内存中释放它.我将 FOO 设置为 NULL.

                  This is clearly a huge amount of space and I want to deallocate it from memory. I set FOO to NULL.

                  这会自动释放内存中的空间吗?或者加载的文本文件占用的内存会一直持续到自动垃圾回收吗?

                  Will this free up that space in memory automatically? or Will the memory taken by the loaded text file be around until automatic garbage collection?

                  推荐答案

                  当你将任何对象的引用设置为null时,它就变成可用进行垃圾回收了.在垃圾收集器实际运行之前,它仍会占用内存.除了在抛出 OutOfMemoryException 之前它肯定会运行并从无法访问的对象中回收内存之外,无法保证 GC 何时运行.

                  When you set the reference of any object to null, it becomes available for garbage collection. It still occupies the memory until the garbage collector actually runs. There are no guarantees regarding when GC will run except that it will definitely run and reclaim memory from unreachable objects before an OutOfMemoryException is thrown.

                  您可以调用 System.gc() 来请求垃圾回收,但这就是它的本质 - 一个请求.运行由 GC 自行决定.

                  You can call System.gc() to request garbage collection, however, that's what it is - a request. It is upto GC's discretion to run.

                  使用 WeakReference 在某些情况下会有所帮助.请参阅 Brian Goetz 的这篇文章.

                  Using a WeakReference can help in some cases. See this article by Brian Goetz.

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

                  上一篇:在 JVM 中测量花费在 GC 上的时间 下一篇:是java原语垃圾收集

                  相关文章

                  <legend id='7Rufp'><style id='7Rufp'><dir id='7Rufp'><q id='7Rufp'></q></dir></style></legend>
                    <bdo id='7Rufp'></bdo><ul id='7Rufp'></ul>
                  1. <tfoot id='7Rufp'></tfoot>

                    <small id='7Rufp'></small><noframes id='7Rufp'>

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