Operations 7 min read

Using VisualVM for JVM Monitoring and Memory Leak Analysis

This article introduces VisualVM, a Java profiling tool bundled with the JDK, explains how to install and use its plugins for monitoring CPU, memory, threads, and garbage collection, and demonstrates step‑by‑step memory‑leak detection and remote Tomcat monitoring with code examples.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Using VisualVM for JVM Monitoring and Memory Leak Analysis

VisualVM is a profiling sub‑project of NetBeans that comes with JDK 6 update 7 and later, providing a graphical interface to monitor threads, memory usage, CPU time of methods, and object allocation details, including reverse stack traces for objects.

The tool can be launched via the jvisualvm.exe executable located in the JDK bin directory. Once started, it offers both local and remote monitoring similar to jconsole, and its UI is organized into system and JVM sections with various tabs.

VisualVM’s functionality can be extended through plugins; common plugins focus on GC monitoring, memory analysis, and thread inspection. Users can install plugins via the main menu Tools → Plugins and select the desired plugins from the “Available Plugins” tab.

The article provides a practical case study for detecting a memory leak. A static HashMap is used to store many TestMemory objects in a loop, with JVM parameters set to -Xms512m , -Xmx512m , -XX:-UseGCOverheadLimit , and -XX:MaxPermSize=50m . The program pauses at several points to allow heap dumps, which are then analyzed with VisualVM’s Visual GC and Sampler tabs.

By comparing heap dumps taken after different execution phases, the analysis shows a continuous increase in TestMemory instances, indicating a memory leak. The “Instances” view reveals that the objects are retained via references from the CyclicDependencies class and the static HashMap , pinpointing the leak source.

For remote monitoring, the article explains how to configure a Tomcat server’s catalina.sh to enable JMX (setting hostname, port, disabling SSL and authentication), then add the remote host in VisualVM, create a JMX connection, and start monitoring the remote JVM.

Overall, VisualVM offers a comprehensive, visual approach to JVM performance monitoring, memory‑leak detection, and remote application analysis, complementing tools like jconsole with richer plugins and easier navigation.

memory-leakperformance analysisJMXJVM monitoringVisualVMJava profiling
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.