how to trace memory leak in Android ?

this post is really a question, doesn't contain the answer Orz


this big question may consist of several items


what is memory leak ? 


how  to monitor Android system memory and performance ?



linux command :


ps -x
top
cat /proc/meminfo


not know exactly : 


dumpsys meminfo proc-id
procrank
time command-line
vmstat


and DDMS (Android SDK tool) !!


Could automatic track memory leak on Android ?


DDMS could help !


but need to do some settings ( group discuss Finding Memory leak in native code )


0. Build libc_debug.so 


1. replace system/lib/libc.so with /system/lib/libc_debug.so 


2. set environment variables 



 $PATH with ~/open_src/prebuilt/linux-x86/toolchain/arm-eabi-XXX/bin
 $ANDROID_PRODUCT_OUT with ~/open_src/out/target/product/



'PATH' is used for getting "arm-eabi-addr2line" and
ANDROID_PRODUCT_OUT for getting the path to /symbol folder. 




3. restart the framework.  


adb shell stop && adb shell start 


4. Add "native=true" to  ~/.android/ddms.cfg


5. start the stand-alone version of DDMS.  -> "Native Heap" 


but just know that there  was an malloc @@ !!


how to avoid memory leak in application ?


from Avoid memory leaks on Android suggestion:




  • Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)
  • Try using the context-application instead of a context-activity
  • Avoid non-static inner classes in an activity if you don’t control their life cycle, use a static inner class and make a weak reference to the activity inside



to be continued ...



留言

Google Search

推薦內容橫式

本月熱門文章

日本旅行 去東京可以在哪邊買羽球相關用品? WEMBLEY/WINDSOR/梭家/Victoria/Alpen TOKYO

[FAANG面試] Amazon/AWS 領導力準則 14 Amazon Leadership Principles

ComfyUI搭配各個Stable Diffusion模型版本的介紹、檔案名稱及相應的目錄結構。

PM到底在做什麼 ? Project Manager, Product Manager 以及 Program Manager的差別

Netflix 勁爆女子監獄 Orange is the New Black /OINTB 成立了 Poussey Washington Fund 這個基金將會幫助更生人及移民人權問題 !!

蔣經國時代 1979年 美麗島事件 回顧

快速上手的ComfyUI與Stable Diffusion生成圖片的cheat sheet

許多深藍人士懷念的兩蔣時代

川普第二次擔任美國總統

日本女子搖滾樂團=Hölderlins的吉他手 高橋聖子 Shoko Takahashi 可能要單飛啦 讓搖滾,性感和舞蹈音樂可以很好地融合在一起

這個網誌中的熱門文章

Android應用開發豆知識:利用 adb 安裝 apk 到裝置上

Android 中文輸入法 官方版 ! Gboard - Google 鍵盤 開始支援注音輸入啦

Google Play 推薦Android app 誠徵App排行榜

北京故宮首訪,一窺清宮秘史 大玉兒 & 甄嬛

[家教][社會觀察] 建中教我的事 沒上建中被父母親折磨? 在建中到底是如何 ...

[FAANG面試] Amazon/AWS 領導力準則 14 Amazon Leadership Principles

Acer ICONIA Smart S300 更新後越來越好 Acer也有出手機?!

[品質控制] 什麼是Sanity test ? 軟體測試常見名詞整理 包含不同部門的測試人員負責範圍

新鮮人找工作:職場名詞解釋 AE FAE Pre-sales Post-sales