gpt4 book ai didi

java - 分析 java 堆转储 : why are enum instances kept in heap?

转载 作者:行者123 更新时间:2023-11-29 10:20:31 25 4
gpt4 key购买 nike

我一直在寻找我的应用程序中的内存泄漏,并发现由于某种原因,枚举实例保留在堆中。

为了模拟它,我在 tomcat 中部署了我的应用程序,对其进行了一些操作,停止它并在 tomcat 上执行 GC(通过 jconsole)。然后进行堆转储,发现了这个:

instance of x.mgbean.quote.Input$Tab@0xe0887c0 (16 bytes)
Class:
class x.mgbean.quote.Input$Tab
Instance data members:
name (L) : VEHICLE (24 bytes)
ordinal (I) : 0
References to this object:
java.util.HashMap$Entry@0xe15f7c0 (24 bytes) : field value
class x.mgbean.quote.Input$Tab (84 bytes) : static field VEHICLE
[Lx.mgbean.quote.Input$Tab;@0xe0887f0 (20 bytes) : Element 0 of [Lx.mgbean.quote.Input$Tab;@0xe0887f0
[Lx.mgbean.quote.Input$Tab;@0xe1541e8 (20 bytes) : Element 0 of [Lx.mgbean.quote.Input$Tab;@0xe1541e8

知道这是怎么发生的吗?

最佳答案

为什么它们不在堆中?与所有其他对象一样,它们是一个类(枚举类)的实例。这并不意味着它们可以被垃圾收集。他们的类持有对每个实例的引用。

关于java - 分析 java 堆转储 : why are enum instances kept in heap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7148611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com