My Oracle Support Banner

Session Data Retained in Java Heap Long after Sessions End (Doc ID 2778368.1)

Last updated on MARCH 31, 2023

Applies to:

Java SE JDK and JRE - Version 8 and later
Information in this document applies to any platform.

Symptoms

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:

  1. Run an application with users establishing and ending sessions until the heap utilization is at about 70%. 

  2. Leave the application running without anything executing on it for a length of time after all sessions have ended. 

  3. Call System.gc() a few times to clear de-referenced (dead) objects from the Java heap. 

  4. Review the GC logs to ensure the Full GCs were run.  
  5. 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

  6. Analyze the heap dump with a memory analyzer, such as Eclipse Memory Analyzer (MAT) to see which session memory is still being referenced

  7. 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.

 

Cause

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
Symptoms
Cause
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.