试图检测 webapp 中的内存泄漏。
- 在崩溃时获取应用程序的堆转储。
- 使用 Eclipse MAT 解析转储。
来自解析的整理信息导致这两个结论 -
- 占用更多内存的对象没有 GC 根。基本上每当 GC 发生时,它们都会被清理掉。
- GC 根下的对象占用的内存要少得多。所以这些可能不是内存泄漏的根本原因(?)。
那么这是否意味着没有泄漏发生?并且由于内存不足错误而发生崩溃?
编辑:添加环境信息
- 我在 tomcat 6 上运行 java webapp。
- webapp基于openreports(报告工具)
添加最大对象的传入引用列表——
这里哈希映射的每个实例都有一个来自 com.opensymphony.xwork2 的引用,它不是 GC 收集的。这可能是问题的根源。因为tomcat日志说-
SEVERE: The web application [/openreports] created a ThreadLocal with key of type [com.opensymphony.xwork2.ActionContext.ActionContextThreadLocal] (value [com.opensymphony.xwork2.ActionContext$ActionContextThreadLocal@7c45901a]) and a value of type [com.opensymphony.xwork2.ActionContext] (value [com.opensymphony.xwork2.ActionContext@3af7dab3]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
SEVERE: The web application [/openreports] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@258c27bd]) and a value of type [com.opensymphony.xwork2.inject.InternalContext[]] (value [[Lcom.opensymphony.xwork2.inject.InternalContext;@1484fc8d]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
编辑:添加 OOM 错误的堆栈跟踪
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3209)
at java.lang.String.<init>(String.java:215)
at java.lang.StringBuffer.toString(StringBuffer.java:585)
at java.io.StringWriter.toString(StringWriter.java:193)
at org.displaytag.tags.TableTag.writeExport(TableTag.java:1503)
at org.displaytag.tags.TableTag.doExport(TableTag.java:1454)
at org.displaytag.tags.TableTag.doEndTag(TableTag.java:1309)
at org.efs.openreports.engine.QueryReportEngine.generateReport(QueryReportEngine.java:198)
at org.efs.openreports.util.ScheduledReportJob.execute(ScheduledReportJob.java:173)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
10:01:04,193 ERROR ErrorLogger - Job (90.70|1338960412084 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.OutOfMemoryError: Java heap space]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3209)
at java.lang.String.<init>(String.java:215)
at java.lang.StringBuffer.toString(StringBuffer.java:585)
at java.io.StringWriter.toString(StringWriter.java:193)
at org.displaytag.tags.TableTag.writeExport(TableTag.java:1503)
at org.displaytag.tags.TableTag.doExport(TableTag.java:1454)
at org.displaytag.tags.TableTag.doEndTag(TableTag.java:1309)
at org.efs.openreports.engine.QueryReportEngine.generateReport(QueryReportEngine.java:198)
at org.efs.openreports.util.ScheduledReportJob.execute(ScheduledReportJob.java:173)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)