Java Heap Retention in java.io.DeleteOnExitHook
Environment
- Red Hat JBoss Enterprise Application Platform
- Red Hat JBoss Web Server (Tomcat)
Issue
Experiencing memory issues with java.io.DeleteOnExitHook. It is consistently a high consumer of memory in our heap.
Resolution
Minimize calls to File.deleteOnExit. Delete files (File.delete) once you are done with them in your application.
Root Cause
- When you call
File.deleteOnExit, the File's path is stored in the DeleteOnExitHook until the JVM terminates/exits. Here is example output from Eclipse Memory Analyzer's Dominator Tree:
Class Name | Shallow Heap | Retained Heap | Percentage
-----------------------------------------------------------------------------------------------------
class java.io.DeleteOnExitHook @ 0x1c93f6dd0 System Class| 8 | 1,239,630,608 | 71.29%
'- java.util.LinkedHashSet @ 0x1c9653a20 | 16 | 1,239,630,600 | 71.29%
'- java.util.LinkedHashMap @ 0x1c9653a30 | 56 | 1,239,630,584 | 71.29%
|- java.util.HashMap$Node[16777216] @ 0x29775f350 | 67,108,880 | 67,108,880 | 3.86%
|- java.util.LinkedHashMap$Entry @ 0x1d16c41b0 | 40 | 184 | 0.00%
|- java.util.LinkedHashMap$Entry @ 0x1d16c4318 | 40 | 184 | 0.00%
|- java.util.LinkedHashMap$Entry @ 0x1d16c45e0 | 40 | 184 | 0.00%
|- java.util.LinkedHashMap$Entry @ 0x1d16c47f8 | 40 | 184 | 0.00%
Total: 5 of 6,502,001 entries; 6,501,996 more
-----------------------------------------------------------------------------------------------------
Category
Tags
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.