Android 記憶體檢查

來源:互聯網
上載者:User

標籤:

Android 記憶體檢查

 

  本文簡單介紹了如何使用 DDMS 和 MAT 工具來對 android 進行記憶體檢查,瞭解 android 記憶體的具體佔用情況。

 

步驟1. 使用 DDMS 觀察記憶體的使用方式

  環境準備:電腦安裝了 android sdk,手機端開啟了 USB 調試開關, 將手機串連 PC。

  可以單獨使用 ddms,或者在 android studio中Tools -> Android -> android device monitor, 選擇待調試的 device 和進程。

 

步驟2. 記憶體使用量異常時 dump hprof files

  正常情況下 allocated size 值都會穩定在一個有限的範圍內,每次 GC 之後都會釋放,如果發現 allocated size 一直增加沒有得到釋放,這說明記憶體佔用存在問題,可能存在記憶體泄露。點擊左側的 dump java heap,匯出 hprof 檔案,假設命名為 test.hprof。

 

步驟3. 使用 MAT 分析 hprof 檔案

(1)首先下載 MAT 工具,MAT 可以是 eclipse 外掛程式,也可以下載一個獨立的應用。

MAT 工具的:http://www.eclipse.org/mat/downloads.php

(2)步驟2中匯出的 hprof 檔案不能直接被 MAT 解析,需要轉換一下:

cmd 進入 sdk\tools 目錄,比如:cd E:\AutoTestProj\AutoTest\tools\android_sdk\tools;

(3)將步驟2中匯出的 test.hprof 拷貝到該目錄下;

(4)運行cmd:hprof-conv  test.hprof  output.hprof

則該目錄下會產生 output.hprof 檔案;

(5)MAT工具匯入 hprof  檔案

file -> open heap dump -> 選擇 output.hprof,可以看到 leak suspects 分析報告。如果發現問題,需要及時和開發溝通解決。

 

Android 記憶體檢查

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.