Android Developer: Heap Viewer demonstration
This demo shows the basic usage of the Heap Viewer tool. Heap Viewer reports in real time what type of objects, how many objects, and their size in Heap memory have been allocated to your application.
Its advantages:
Prerequisites
Bytes ----------------------------------------------------------------------------------------
A mobile phone that runs the Android or higher startup developer options.
Application code, use your own code, or Sunshine sample program.
Use Heap Viewer
Bytes -----------------------------------------------------------------------------------------
Connect your device to your computer.
Open your application in Android Studio, build the source code, and run it on your device or simulator.
Start Android Device Monitor: Tools-> Android Device Monitor in Android Studio.
You can also start Memoery Monitor in Android Studio: Click the Android tab in the lower left corner of the application. Displays the CPU and Memory Monitor views.
Figure 1. Start Memory Monitor
In the device and application drop-down list, select the app you want to monitor.
Figure 2. Steps for using Heap Viewer
To save heap dump, click the Dump Java Heap icon. The Heap snapshot file named Snapshot-yyyy.mm.dd-hh.mm.ss.hprof is on the Captures tab.
Figure 3. Update heap
Note that Heap update will update the message after each GC of the device.
Click the Initiate CG icon to trigger a garbage collection event.
Figure 4. Triggering GC (garbage collection)
Double-click the heap snapshot file to open the heap viewer and view the details of the memory currently allocated in the heap.
Figure 5. Heap Viewer output example