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

推薦內容橫式

本月熱門文章

國民黨陳玉珍翁曉玲自肥條款 可望再出現連戰兩億公務員? 各種荒腔走板的陳玉珍、翁曉玲 真是令人傻眼

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

2024/12 國民黨的黑箱國會造成台灣民主大退步 選罷法 ... 還有真實作用嗎

綠能貪污原來大多是國民黨民眾代表

悲痛!XREX區塊鏈金融犯罪調查師陳梅慧Miffy殞落,揭露虛擬貨幣犯罪背後的黑幕

中華民國國軍辛苦了 因應中共軍演努力監視

常見詐騙案例犯罪手法及預防方式一覽表 (持續更新)

20241123 BoA : One's Own in TAIPEI 難得一見的BoA來台灣演出

金融犯罪調查專家陳梅慧 離奇車禍死亡 疑點整理

[FAANG面試] 如何準備Google Technical Program Manager (TPM) 面試

這個網誌中的熱門文章

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