Tomcat - their classes from previous runs are still loaded into memory

when stop my project, tomcat will say:

The following web applications have been stopped (rebooted, not deployed), but their classes from previous launches are still loaded into memory, which causes a memory leak (use the profiler to confirm).

Where do we find which classes are remembered?

Please help me.

+4
source share
2 answers

You can run jmap -histo , which will show you the loaded classes.

Another way is to enable the download of debugging information and run some scripts to find out what is left to load.

+8
source

When this happens, there is usually something in memory that β€œbinds” WebappClassLoader (the class loader that is responsible for loading the classes for the instance of your webapp) into memory. If you reload your webapp several times, you can see the number of instances of WebappClassLoader increasing by 1 for each reboot you are doing. This is usually not a leak in Tomcat, but a leak directly in your webapp code, a leak in your library, or a leak caused by several specific Java API calls that do stupid things.

First read the following: http://people.apache.org/~markt/presentations/2010-11-04-Memory-Leaks-60mins.pdf . This is a great description of what exactly is happening.

Secondly, use the profiler to determine what holds references to objects loaded by your WebappClassLoader. Many times, simply using the ServletContextListener, you can clear these links when the webapp stops.

Thirdly, if you find that there is a leak from the library you are using, report it. If you find a leak emanating from a class in the JRE, check out the use cases for JreMemoryLeakPreventionListener: http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html#JRE_Memory_Leak_Prevention_Listener_-_org.apache.catalemorycoreLeenerener--_org.apache.catalemorycoreLeener_Jorg.apache.catalinacore . If there is no way for what you find, please drop the Tomcat users and let us know what is missing: we will add it.

+7
source

Source: https://habr.com/ru/post/1414385/


All Articles