Android Developer: Heap Viewer demonstration

Source: Internet
Author: User

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:

  • Get the feeling of how your application allocates and releases memory.

  • Determine Memory leakage.

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 -----------------------------------------------------------------------------------------

  1. Connect your device to your computer.

  2. Open your application in Android Studio, build the source code, and run it on your device or simulator.

  3. 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

    1. In the device and application drop-down list, select the app you want to monitor.

      Figure 2. Steps for using Heap Viewer

      1. 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

        1. Note that Heap update will update the message after each GC of the device.

        2. Click the Initiate CG icon to trigger a garbage collection event.

          Figure 4. Triggering GC (garbage collection)

          1. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.