You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perform several (5-10) restarts of the application with Tomcat manager
As a result, we observe a metaspace leak (if a value of XX:MaxMetaspaceSiz is set and was reached, we get an exception)
Analysis
Create Heap Dump (for example, using jvisualvm)
Open the dump file with jvisualvm or MemoryAnalyzer
Select all objects of ParallelWebappClassLoader type
The number of objects is equal to the number of restarts plus active application instances in Tomcat
Select «Path to GC Root» for inactive ParallelWebappClassLoader
We can see the Thread (reference to ParallelWebappClassLoader) is stored in ApplicationShutdownHooks. Because of this reference, the GC cannot delete this ParallelWebappClassLoader instance and free metaspace
Causes
The thread that holds ParallelWebappClassLoader is created in the constructor of the class SpringApplicationShutdownHook (line 74)
The object of SpringApplicationShutdownHook is created when loading the SpringApplication type (line 203)
Since every restart of the application (from the tomcat admin panel) create new classloader and initialize SpringApplication type, which causes memory leak.
Steps to reproduce:
Analysis
Causes