Android内存管理(7)在AS中查看内存和cpu情况

Memory and CPU monitor

  Android Studio provides a memory and CPU monitor view so you can more easily monitor your app's performance and memory usage to track CPU usage, find deallocated objects, locate memory leaks, and track the amount of memory the connected device is using. With your app running on a device or emulator, click the Android tab in the lower left corner of the runtime window to launch the Android runtime window. Click the Memory or CPU tab.

        Figure 4. Monitor memory and CPU usage.

Heap dump

  When you're monitoring memory usage in Android Studio you can, at the same time, initiate garbage collection and dump the Java heap to a heap snapshot in an Android-specific HPROF binary format file. The HPROF viewer displays classes, instances of each class, and a reference tree to help you track memory usage and find memory leaks.

          Figure 5. HPROF viewer with heap dump.

  To create a snapshot of the Android app heap memory, click the Dump Java Heap icon () in the Memory Monitor. Android Studio creates the heap snapshot file with the filename Snapshot-yyyy.mm.dd-hh.mm.ss.hprof in the Captures tab. Double-click the heap snapshot file to open the HPROF viewer.

  To convert a heap dump to standard HPROF format in Android Studio, right-click a heap snapshot in the Captures view and select Export to standard .hprof.

Allocation tracker

  Android Studio allows you to track memory allocation as it monitors memory use. Tracking memory allocation allows you to monitor where objects are being allocated when you perform certain actions. Knowing these allocations enables you to adjust the method calls related to those actions to optimize your app's performance and memory use.

        Figure 6. Allocation tracker.

 

  For information about tracking and analyzing allocations, see Memory Monitor.

 

posted @ 2016-03-22 15:59  f9q  阅读(1937)  评论(0编辑  收藏  举报