Session Data Retained in Java Heap Long after Sessions End
(Doc ID 2778368.1)
Last updated on JULY 18, 2021
Applies to:Java SE JDK and JRE - Version 8 and later
Information in this document applies to any platform.
Some Java application session objects remain in the Java heap long after those sessions have ended. It is expected that the session objects are de-referenced and ready for garbage collection when the session ends, but mulitple full garbage collections (Full GCs) do not clear the objects from the heap memory.
The following steps are used to verify session objects remain in the heap:
- Run an application with users establishing and ending sessions until the heap utilization is at about 70%.
- Leave the application running without anything executing on it for a length of time after all sessions have ended.
- Call System.gc() a few times to clear de-referenced (dead) objects from the Java heap.
- Review the GC logs to ensure the Full GCs were run.
- Dump the heap. There are several ways to pull a heap dump:
- Run the command jcmd <pid/main class> GC.heap_dump heapdump.dmp
- Run the command jmap -dump:format=b,file=snapshot.jmap <pid>
- Run jconsole and connect to the Java process, then choose the option to dump the heap
- Run JDK Mission Control with the jmc command, select the running application from the JVM Browser tab, and choose the option to dump the heap
- Analyze the heap dump with a memory analyzer, such as Eclipse Memory Analyzer (MAT) to see which session memory is still being referenced
- Use Object Query Language (OQL) to query the class instances and "select * from <class name>" to verify that memory is still in the heap dump from sessions that already finished.
To view full details, sign in with your My Oracle Support account.
Don't have a My Oracle Support account? Click to get started!
In this Document