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

    <tfoot id='Hxp1G'></tfoot>

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

    3. <legend id='Hxp1G'><style id='Hxp1G'><dir id='Hxp1G'><q id='Hxp1G'></q></dir></style></legend>

    4. 我怎样才能弄清楚是什么保留了未释放的对象?

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

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

                本文介绍了我怎样才能弄清楚是什么保留了未释放的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我们的一个程序有时会在一个用户的机器上出现 OutOfMemory 错误,但在我测试它时当然不会.我只是用 JProfiler 运行它(在 10 天评估许可证上,因为我以前从未使用过它),并过滤我们的代码前缀,总大小和实例数量的最大块是特定简单类的 8000+ 个实例.

                One of our programs is sometimes getting an OutOfMemory error on one user's machine, but of course not when I'm testing it. I just ran it with JProfiler (on a 10 day evaluation license because I've never used it before), and filtering on our code prefix, the biggest chunk both in total size and number of instances is 8000+ instances of a particular simple class.

                我单击了 JProfiler 上的垃圾收集"按钮,我们其他类的大多数实例都消失了,但这些特定的实例没有.我再次运行测试,仍然在同一个实例中,它创建了 4000 多个该类的实例,但是当我单击垃圾收集"时,这些实例消失了,留下了 8000 多个原始实例.

                I clicked the "Garbage Collect" button on JProfiler, and most instances of other classes of ours went away, but not these particular ones. I ran the test again, still in the same instance, and it created 4000+ more instances of the class, but when I clicked "Garbage Collect", those went away leaving the 8000+ original ones.

                这些实例确实会在不同阶段陷入不同的集合中.我假设它们没有被垃圾收集这一事实一定意味着某些东西正在持有对其中一个集合的引用,因此它正在持有对对象的引用.

                These instances do get stuck into various Collections at various stages. I assume that the fact that they're not garbage collected must mean that something is holding onto a reference to one of the collections so that's holding onto a reference to the objects.

                有什么建议可以让我弄清楚参考资料中的内容是什么?我正在寻找有关在代码中寻找什么的建议,以及在 JProfiler 中找到它的方法(如果有).

                Any suggestions how I can figure out what is holding onto the reference? I'm looking for suggestions of what to look for in the code, as well as ways to find this out in JProfiler if there are.

                推荐答案

                转储堆并检查它.

                我确信有不止一种方法可以做到这一点,但这里有一个简单的方法.此说明适用于 MS Windows,但也可在其他操作系统上执行类似步骤.

                I'm sure there's more than one way to do this, but here is a simple one. This description is for MS Windows, but similar steps can be taken on other operating systems.

                1. 如果您还没有 JDK,请安装它.它带有一堆简洁的工具.李>
                2. 启动应用程序.
                3. 打开任务管理器并找到 java.exe(或您正在使用的任何可执行文件)的进程 ID (PID).如果默认情况下未显示 PID,请使用 View > Select Columns... 添加它们.
                4. 使用 jmap 转储堆.
                5. 在您生成的文件上启动 jhat 服务器并打开浏览器到 http://localhost:7000(默认端口为 7000).现在您可以浏览您感兴趣的类型以及实例数量、引用它们的内容等信息.
                1. Install the JDK if you don't already have it. It comes with a bunch of neat tools.
                2. Start the application.
                3. Open task manager and find the process id (PID) for java.exe (or whatever executable you are using). If the PID's aren't shown by default, use View > Select Columns... to add them.
                4. Dump the heap using jmap.
                5. Start the jhat server on the file you generated and open your browser to http://localhost:7000 (the default port is 7000). Now you can browse the type you're interested in and information like the number of instances, what has references to them, etcetera.

                这是一个例子:

                C:dump>jmap -dump:format=b,file=heap.bin 3552
                
                C:dump>jhat heap.bin
                Reading from heap.bin...
                Dump file created Tue Sep 30 19:46:23 BST 2008
                Snapshot read, resolving...
                Resolving 35484 objects...
                Chasing references, expect 7 dots.......
                Eliminating duplicate references.......
                Snapshot resolved.
                Started HTTP server on port 7000
                Server is ready.
                

                要解释这一点,了解一些 数组类型命名法 Java 使用 - 就像知道 class [Ljava.lang.Object; 真的意味着 Object[] 类型的对象.

                To interpret this, it is useful to understand some of the array type nomenclature Java uses - like knowing that class [Ljava.lang.Object; really means an object of type Object[].

                这篇关于我怎样才能弄清楚是什么保留了未释放的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如果 JVM 在进行 GC 时不断移动对象,它如何解析引用? 下一篇:GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时?

                相关文章

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

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

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

                1. <tfoot id='GWKxO'></tfoot>