π A complete developer-friendly guide and hands-on toolkit to analyze, troubleshoot, and optimize Java memory usage using heap dumps and modern profilers like JProfiler,
jmap
, and Eclipse MAT.
This repository is your go-to guide for understanding Java heap dumps, analyzing them using JProfiler, and diagnosing memory leaks or performance bottlenecks. Whether youβre debugging a production crash or fine-tuning memory usageβthis toolkit has you covered.
Tool | Purpose | Link |
---|---|---|
π§° JProfiler | Professional-grade heap dump analysis | JProfiler |
π§ͺ jmap | JVM CLI tool to generate heap dumps | jmap Docs |
π¬ Eclipse MAT | Free memory analyzer for .hprof |
MAT Download |
π οΈ VisualVM | Lightweight profiling/debugging tool | VisualVM |
jmap -dump:format=b,file=heapdump.hprof <PID>
<PID>
is the Java process ID.heapdump.hprof
is the name of the output file.import com.sun.management.HotSpotDiagnosticMXBean;
import java.lang.management.ManagementFactory;
public class HeapDumpExample {
public static void main(String[] args) throws Exception {
HotSpotDiagnosticMXBean mxBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
mxBean.dumpHeap("heapdump.hprof", true);
System.out.println("Heap dump created!");
}
}
File β Open Snapshot
.hprof
fileStart analyzing with:
Heap Walker
Reference Graph
Dominator Tree
GC Roots
Allocation Call Tree
View | Purpose |
---|---|
Classes View | Identify classes with max memory footprint |
Instances View | Inspect each object instance and size |
Reference Graph | Understand object relationships |
GC Roots | Discover objects keeping others alive |
Dominator Tree | Visualize memory retention hierarchy |
Allocation Tree | Analyze object allocation paths |
Term | Meaning |
---|---|
Heap | The memory area where Java objects live |
Shallow Size | Memory directly consumed by the object |
Retained Size | Total memory retained if this object and its exclusives were GCβd |
GC Root | Root reference point in JVM memory graph |
Dominator | Object whose deletion would make child objects unreachable |
Reference Chain | Path from GC root to the object, useful for memory leak analysis |
Object A retains B and C
βββ B
βββ C
If B and C are only accessible through A,
then A's retained size = shallow size of A + B + C
Metric | What it Tells You | Example |
---|---|---|
Shallow Size | Objectβs own memory | 40 bytes |
Retained Size | Memory freed if object + dependents removed | 40 + B (30) + C (20) |
Map
, List
) with old or unnecessary dataUse JProfiler features like:
#Java #HeapDump #JProfiler #MemoryLeak #GC #MAT #MemoryOptimization #JVM #ReferenceGraph #PerformanceTuning
Pull requests welcome! Feel free to add:
If this helped you:
Crafted with π by @Sharique55