I am (test) running my web app in Tomcat 7 and using their "Find Leak" button and of course it complains about memory leak when I stop / undeploy.
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): /LeakyWebApp
So I used Java VisualVM (my first time trying this out)
on Tomcat startup with no deployment: http://img15.imageshack.us/img15/4441/tomcatstartup.jpg
My web app involves:
- Quartz 1.8.5
- Hibernate 3.6.3
- JAXB 2.2.4
- Salesforce API
- log4j
Immediately after deployment: http://img850.imageshack.us/img850/2951/tomcatafterdeployment.jpg
So I noticed it complains about Quartz and I also read somewhere to close Hibernate Session Factory on servlet destroy.
On stop / undeploy, The Visual VM does show the Quartz thread stopped, but the tomcat log says
"appears to have start a thread named ... and has failed to stop it"
So I created a new ServletContextListener and on contextDestroyed I call to Quartz factory scheduler to shutdown and also call close on Hibernate Session Factory. and doing another deploy/undeploy, there's no more complain from the tomcat log about Quartz thread problem as above.
However, when I use "find leaks" it still complains about the same thing
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): /LeakyWebApp
Then i found another complain about JDBC driver (I have mysql connector jar in my war), so I tried removing that, the complain from tomcat log disappear but the "Find Leaks" still say the same thing that my web app has memory leaks
So my question would be - what else should I be looking at? and/or how can I use the Visual VM better to detect what's going?
Thanks
EDIT: I fixed the issue with Quartz based on the post by David Feitosa, I was missing
<init-param>
<param-name>wait-on-shutdown</param-name>
<param-value>true</param-value>
</init-param>
from the Quartz properties in web.xml.
However - I still have issue with the JDBC driver - I need it for my web app, and seems like I have 2 solutions based on the answers from: To prevent a memory leak, the JDBC Driver has been forcibly unregistered
- Put the mysql-connector jar in the tomcat/lib
- Manually un-register the driver in the contextDestroyed.
Which way should I go and what's the best practice for this?