To capture a heap dump interactively, run a debuggable build of your app, open Android Studio’s Profiler, and select Analyze Memory Usage (Heap Dump). For a shell-based capture, use ADB’s am dumpheap command; for a capture at a specific point in your app’s code, use Debug.dumpHprofData(). A heap dump is a point-in-time view of Java objects, so compare captures around a repeatable action to investigate objects that remain reachable unexpectedly.
Choose a capture method
| Method | Best for | Key constraint |
|---|---|---|
| Android Studio Profiler | Interactive capture and immediate class and instance inspection | Heap capture requires a debuggable app; capture temporarily increases Java memory. |
ADB am dumpheap |
Repeatable shell commands, automation, or capturing a file for later analysis | The app must be debuggable or profileable with shell profiling enabled; options can depend on Android version. |
Debug.dumpHprofData() |
Capturing at a specific point in app execution | Requires an output path and error handling; the call may cause garbage collection. |
| Perfetto | Correlating a Java heap reference graph with system trace events | Its heap output omits actual field contents and is viewed in Perfetto UI rather than AHAT. |
Capture a heap dump in Android Studio
- Build and run the app using a debuggable configuration on a device or emulator. Android Studio’s regular heap-dump workflow requires a debuggable app; a profileable release build alone does not enable every profiling task, including heap capture. See Android Studio Memory Profiler and Inspect your app.
- With the app running, open the Profiler tool window in Android Studio and select the app process.
- Select Analyze Memory Usage (Heap Dump). Android Studio captures the current heap and opens the dump for inspection.
- In the class list, select a class to inspect its instances. Review fields and references to understand which objects remain reachable.
For a more useful comparison, reproduce the same user flow and capture after the point where objects should have been released. Android’s guide notes that a longer session can make retained objects easier to spot. Collection happens inside the app process, so Java memory use can temporarily rise during capture; Android documents this as normal.
Capture and pull a dump with ADB
For a running app with package name com.example.app, the basic sequence is:
adb shell am dumpheap com.example.app /data/local/tmp/heap.hprof
adb pull /data/local/tmp/heap.hprof .
The first command writes the heap dump on the device; the second copies it to the current directory on your computer. The app must be built with <profileable android:shell="true"/> or <debuggable>. Use the actual package or process identifier and a device path writable in the app’s execution environment. The ADB reference documents the command form as dumpheap [options] process file; consult its option and API-level notes for the target device: Android Debug Bridge (ADB) and Manage your app’s memory.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
Including bitmap pixel data
If you need bitmap pixel data stored in native memory, Android documents a bitmap option for including it in the heap dump. The memory guide demonstrates -b png and notes that this inclusion is needed for AHAT bitmap analysis. The ADB reference lists bitmap dumping as available on API level 35 and higher, so check the device’s Android version and current command documentation before relying on it.
Capture from app code
When the best capture moment is determined by app behavior, call Debug.dumpHprofData(fileName) with a full output pathname. The method writes an HPROF file; plan how that file will be stored and retrieved. The API can cause garbage collection and may throw IOException if it cannot open or write the file, or UnsupportedOperationException if the VM does not support HPROF. See the Android Debug API reference.
Rank #2
Use Perfetto when you need system-trace context
Perfetto can capture Java heap dumps as part of a system trace when the trace configuration enables the android.java_hprof data source. This is useful when you need to correlate the object reference graph with system events. Unlike a standard HPROF dump, this output contains the reference graph but not actual field contents such as strings or byte arrays. Android directs you to view it in Perfetto UI, not AHAT; see Manage your app’s memory.
Understand what the dump shows
A heap dump is a snapshot of Java heap objects at the time of capture. Android Studio groups allocations by class or package and lets you inspect classes, instances, fields, and references. A reference path helps explain why an object is still reachable; a single snapshot does not establish that the object is an unintended leak.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute- Shallow size is the Java memory used directly by an object.
- Retained size represents memory kept reachable through instances of that type.
- Native size reports native memory where supported. Android Studio’s native-size column is unavailable on Android versions below 7.0.
To investigate possible accumulation, compare a baseline dump with another captured after repeating the same action. Look for unexpected instances and inspect their reference paths to identify what keeps them reachable. Android describes heap dumps as a way to examine memory use and identify leaks or allocation behavior that can contribute to stutter, freezes, or crashes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Export, import, and convert heap dumps
Android Studio can export or import a heap-dump recording from Past Recordings as an .hprof file. Android HPROF format may need conversion before use with Java SE analyzers such as jhat. Android’s documentation directs users to hprof-conv in the SDK’s platform-tools directory, passing the input and output filenames. Perfetto heap dumps are trace data and use the Perfetto viewing workflow instead of the standard HPROF/AHAT path. See Android Studio Memory Profiler and Manage your app’s memory.
Quick Recap
Best Value
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.

