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

为了模拟它,我已经将我的应用程序部署在了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


知道如何发生吗?

最佳答案

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

08-17 18:37