分析java heapdumps:为什么枚举实例保存在堆中?

Ste*_*ote 1 java enums heap-memory heap-dump

我一直在寻找我的应用程序中的内存泄漏和fhat与jhat,由于某种原因,枚举的实例保存在堆中.

为了模拟它,我已经在tomcat中部署了我的应用程序,稍微使用它,停止它并在tomcat上执行GC(通过jconsole).然后拿了一个heapdump发现了这个:

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
Run Code Online (Sandbox Code Playgroud)

知道怎么会这样吗?

JB *_*zet 6

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

  • 你取消了它,还是只是停下来?也许Tomcat在取消部署应用程序之前不会使类加载器无法访问? (2认同)