Java Heap memory leak

Start DDMS from:

C:\Program Files (x86)\Android\android-sdk\tools\ddms.bat

Select the faulting App.
Click on the "Show heap updates" green icon.
Open the "VM Heap" tab, click on "Cause GC" to clean Heap. Look at allocations.

After some cycles, click on "Dump HPROF file" green icon.
Concert the file to Java format using:

"C:\Program Files (x86)\Android\android-sdk\tools\hprof-conv.exe" <hprof> <hprof converted>

Parse the converted Hprof file using Memory Analyser:

http://www.eclipse.org/mat/

Note:

- Shallow memory: own object memory
- Retained memory: dominated sub objects size

Select one suspicious leak in the Dominator Tree, then Right Click / Path to GC Roots / exclude weak references

 

 

Tricks:

- MainActivity.*: should have only 1 instance
- sub-objects should be non static
- sub-classes should be static

 

posted on 2014-12-13 10:01  阿加  阅读(274)  评论(0)    收藏  举报

导航