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

推薦內容橫式

本月熱門文章

鋼鐵韓粉站出來 讓韓國瑜每天唱歌喝酒好不好

捐款支持義大利靈醫會 一起來幫助他們 就像當初教士來台灣協助我們一樣 !!

香港事件回顧 2020/08/10 前眾志成員周庭及壹傳媒創辦人黎智英被捕 今日累計10人被捕

黑金? 不得不提前總統馬英九大姊馬以南 吳敦義 林益世

從台灣省長宋楚瑜到台北市長柯文哲,可以說 宋楚瑜 2.0 就是柯文哲

「港版國安法」,法律將會放在《基本法》附件三在港實施,而非就《基本法》23條立法

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

除了兒福聯盟 還有其他團體是努力守護孩子們 芥菜種會愛心育幼院 及忠義育幼院 都需要大家幫忙

這個網誌中的熱門文章

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