Tomcat memory leak Problem Analysis, tomcatleak
Analysis of Tomcat memory leak problems
The following web applications were stopped (reloaded, undeployed), but their classes from previous runs are still loaded in memory, thus causing a memory leak (use a profiler to confirm):
When you use Maven to redeploy a project on Tomcat, the memory leaks because the previous classes has not been uninstalled and still exists in the jvm memory,
However, some people say that they should stop the project before uninstalling the project, and then undeploy will not see the memory leak.
Stack Overflow:
If you want to make sure not to cause leaks you have to do the following:
Make sure your web application does not use any java classes that are in the web container shared libraries. if you have any shared libraries, make sure there is no strong references to the objects in those libraries Avoid using static variables, especially on java objects like HashTable, Sets, etc. if you need to, make sure that you call remove to release the objects with the maps, lists...
Here is also a good article on ThreadLocal and MemoryLeaks-https://blog.arendsen.net/index.php/2005/02/22/threadlocals-and-memory-leaks-revisited/
1. Avoid using the libraries in the container. If you need to use them, avoid using strong references to those libraries.
2. Avoid using static variables, especially containers such as map and set as static variables.