Analysing memory leaks in tomcat with jvisualvm and eclipse MAT

This tutorial is going to show step by step guide on finding memory leaks in tomcat. Usually memory leaks happens when tomcat cannot free the memory used by the deployed webapp on undeploy.

Tools for ananlysing memory leaks

So the tools that we are going to use are quite easily available and most widely used.

  1. jvisualvm
    • This comes with the java installation and is very handy.
  2. Eclipse MAT – plugin for eclipse
    • Eclipse  MAT  plugin for eclipse: It is a very powerful tool to analyse memory issues.

 

Step By Step Guide

2. Create the heap dump of the remote vm using jvisualvm. The heap dump option is in the Memory tab.
memory dump using visiualvm
memory dump using visiualvm

3. It will ask for the location of the file to which the heapdump should be stored. By default it stores the heapdump file in the tomcat/tmp folder.
4. You may need to change the permissions of the file for using it.
5. Then the next step would be to copy it to your desired location.
6. Go to eclipse and File > Open File and select the file
7. You will see dialog as below

Leak Suspects Report Wizard
Leak Suspects Report Wizard
8.  Select Leak Suspects Report from the above dialog and click Finish
9. This will create a report like below
Memory Leaks Suspects Report
Leak Suspects Report

 

10.  On this report you can click on Details to see the stacktrace of the hanging thread.
I have already done some memory analysis at wrong configuration of log4j2  , you can see here how the stacktrace looks like.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.