To find a Java memory leak, track the heap’s live set after garbage collection, capture evidence while memory is growing, and trace which references keep objects alive. Use Java Flight Recorder (JFR) and JDK Mission Control (JMC) to see change over time; use a heap dump and Eclipse Memory Analyzer (MAT) to inspect retained objects and their paths to GC roots. If heap data does not explain process growth, investigate native and JVM-internal memory separately. Then fix the responsible ownership or lifecycle issue and repeat a comparable workload to confirm the live set stabilizes.
How to tell whether memory is leaking
A memory leak is memory that remains reachable after the application no longer needs it. A large heap reading by itself does not establish a leak: a busy application may use substantial memory temporarily, and the JVM may retain heap capacity for reuse.
Watch the live set—the heap still in use after garbage collection—across representative workloads. A live set that keeps rising after old collections, especially alongside increasingly frequent garbage collection, is stronger evidence of accumulation than a single usage reading. Oracle’s Java SE 12 memory-leak guide describes this pattern and notes that slowdown, frequent collections, and eventual OutOfMemoryError can be warning signs.
Record the workload, JVM vendor and version, heap settings, and when the growth occurs. Those details make later recordings or dumps comparable and help distinguish a persistent trend from a temporary spike.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Read the exact OutOfMemoryError detail
OutOfMemoryError: Java heap space means the JVM could not satisfy a heap allocation. Possible causes include an undersized heap, unintended retention, or application code that holds more objects than expected; the message alone does not prove a leak. Other error details may point to native allocation failure or excessive time spent in garbage collection, which require different diagnosis. Check the exact message and the memory pool involved before changing -Xmx.
Capture evidence while growth is happening
JFR can record runtime events and object samples over time, but it must be active during the period when the leak occurs. Oracle’s Java SE 26 Troubleshooting Guide states: “To detect a memory leak, JFR must be running at the time that the leak occurs.” Oracle says JFR’s overhead is “less than 1%” in its documented context and that it is designed to be safe to leave on in production; this is not a guarantee for every JVM build or workload.
Start or dump a recording
To start a recording with the application, Oracle documents the JVM option -XX:StartFlightRecording. For a running process, the guide documents dumping a recording with jcmd:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
jcmd pid JFR.dump filename=recording.jfr path-to-gc-roots=true
Replace pid with the target JVM’s process ID. Root-path data can help explain retention, but collecting paths takes time; enable it when a leak is suspected and account for the added diagnostic cost. Verify command and option availability for the target JVM vendor and release.
Recommended Free Tools
Inspect JFR data in JMC or with the jfr command
Open the recording in JMC and examine Live Objects and old-object samples. Compare class instance counts as well as shallow heap size across the recording or across comparable recordings: many small objects can keep a much larger object graph alive. Old Object Sample events may include allocation time, allocation stack, and a path to a GC root.
You can also print old-object samples from the command line:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
jfr print --events OldObjectSample recording.jfr
Allocation samples are clues, not proof that a particular site is responsible. A slow leak or allocation site may not appear in sampled events, so the absence of a relevant sample does not rule out a leak.
Use a heap dump to find what is retaining objects
A heap dump is a snapshot: it helps answer which objects and reference chains keep memory alive at that moment. Open the dump in Eclipse MAT and start with the Dominator Tree, which ranks objects by retained size. Retained size represents the memory that would become collectible if the relevant object or reference owner were removed.
Follow the object graph
- Use the Dominator Tree to locate objects with large retained sizes. If no single object stands out, group results by class or class loader.
- Use Top Consumers to identify large groups of objects.
- For a suspect object, open Paths to GC Roots and trace the reference chain that keeps it reachable.
- Review the Leak Suspects report as a way to surface candidates, then check whether the retention is actually unintended for the application’s workload and lifecycle.
MAT’s finding-memory-leak guidance describes these analysis queries. Its introduction says the tool can analyze productive heap dumps containing hundreds of millions of objects and calculate retained sizes; that capability does not guarantee a particular analysis time or resource requirement for every dump.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Check native and JVM-internal memory when the heap does not explain growth
The Java heap is only part of a process’s memory footprint. If process memory grows while heap occupancy does not account for it, investigate native and JVM-internal categories rather than increasing the heap without evidence. Oracle’s Java SE 26 guide covers Native Memory Tracking (NMT) and using it to detect memory growth. NMT can help classify JVM memory; native allocation diagnosis may also require platform-specific tools.
JNI libraries and other native code can allocate memory outside the Java heap. Oracle’s Java SE 12 guide notes that native leak techniques vary by platform and that JNI allocations and frees can be instrumented. Class-loader or metaspace growth, excessive finalization, and native library allocations are other distinct problems; use evidence from the relevant memory domain to choose the next diagnostic step.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Choose the diagnostic method by the question
| Method | Best evidence | What to inspect | Trade-off |
|---|---|---|---|
| JFR with JMC | Time-based runtime record and object samples | Live Objects, old-object samples, class growth, allocation and root context | Must be running during the leak window; collecting GC-root paths adds diagnostic cost. Oracle describes JFR as low overhead in its Java SE 26 guide. |
| Heap dump with Eclipse MAT | Detailed object graph at one point in time | Retained size, dominators, top consumers, paths to GC roots, suspect report | Large snapshots can require substantial storage and analysis resources; there is no universal threshold for every dump. |
| NMT and native tools | JVM-internal and native allocation categories | NMT categories and native or JNI allocation/free paths | Use when heap evidence does not explain process growth; tools and procedures vary by platform. |
JFR and heap dumps complement one another: JFR helps show what changes over time, while MAT helps explain what a snapshot’s references retain. JMC and MAT therefore answer related but different questions.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Fix the retention or allocation lifecycle, then verify it
Use the retaining path or native allocation evidence to identify the owner whose lifetime exceeds the object’s useful lifetime. Investigation targets can include unbounded caches or collections, listeners or callbacks that are never deregistered, static references, long-lived thread locals, and class loaders that remain reachable. These are possibilities to check, not a ranking of causes. If evidence points to native allocations, correct the native or JNI ownership and freeing path instead.
After changing the responsible code or lifecycle, repeat a comparable workload using the same observation and capture methods. A fix is supported when the previously accumulating classes, retaining path, or native allocations no longer grow and post-GC live-set behavior stabilizes. No single heap-size change or call to System.gc() substitutes for identifying and correcting the cause.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

