Details
-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
8, 9, 10, 11
-
x86_64
-
linux
Description
A DESCRIPTION OF THE REQUEST :
It is not possible (without using reflection) to clear the references held in ObjectStreamClass$Caches. Such a use of reflection is strongly discouraged in Java 9 onwards.
A method is requested that removes all classes from the caches that have been loaded by the given class loader or a descendant.
JUSTIFICATION :
One of the features of Apache Tomcat is detection of memory leaks in web applications. For this detection to work, it is necessary that all valid/expected references to a web application class loader can be removed. A combination of a WeakReference to the web application class loader and an explicit GC call then enables Tomcat to determine if any unexpected references have been retained to the web application class loader which would indicate a memory leak.
The references retained in ObjectStreamClass$Caches trigger a false positive in Tomcat's memory leak detection. It is necessary to clear those references for the detection to work correctly. An API to do this is requested.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Something along the lines of this API:
ObjectStreamClass.clearCaches(ClassLoader classLoader)
that then did the equivalent of cleanUpLeakingObjects() in https://github.com/markt-asf/memory-
leaks/blob/master/src/org/apache/markt/leaks/io/ObjectStreamClassLeak.java
ACTUAL -
The clean-up has to be performed via reflection.
---------- BEGIN SOURCE ----------
This class demonstrates the leak:
https://github.com/markt-asf/memory-
leaks/blob/master/src/org/apache/markt/leaks/io/ObjectStreamClassLeak.java
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See the code in cleanUpLeakingObjects()
It is not possible (without using reflection) to clear the references held in ObjectStreamClass$Caches. Such a use of reflection is strongly discouraged in Java 9 onwards.
A method is requested that removes all classes from the caches that have been loaded by the given class loader or a descendant.
JUSTIFICATION :
One of the features of Apache Tomcat is detection of memory leaks in web applications. For this detection to work, it is necessary that all valid/expected references to a web application class loader can be removed. A combination of a WeakReference to the web application class loader and an explicit GC call then enables Tomcat to determine if any unexpected references have been retained to the web application class loader which would indicate a memory leak.
The references retained in ObjectStreamClass$Caches trigger a false positive in Tomcat's memory leak detection. It is necessary to clear those references for the detection to work correctly. An API to do this is requested.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Something along the lines of this API:
ObjectStreamClass.clearCaches(ClassLoader classLoader)
that then did the equivalent of cleanUpLeakingObjects() in https://github.com/markt-asf/memory-
leaks/blob/master/src/org/apache/markt/leaks/io/ObjectStreamClassLeak.java
ACTUAL -
The clean-up has to be performed via reflection.
---------- BEGIN SOURCE ----------
This class demonstrates the leak:
https://github.com/markt-asf/memory-
leaks/blob/master/src/org/apache/markt/leaks/io/ObjectStreamClassLeak.java
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See the code in cleanUpLeakingObjects()
Attachments
Issue Links
- duplicates
-
JDK-8277072 ObjectStreamClass caches keep ClassLoaders alive
-
- Closed
-
- relates to
-
JDK-8277072 ObjectStreamClass caches keep ClassLoaders alive
-
- Closed
-