The use of tools: Android Studio 2.0 Preview, Android Device Monitor, MAT (Memory Analyzer).
Click on "Android Device Monitor" Android Studio toolbar
After opening the application process is selected, then click on the "Update heap", then click on each activity applied repeatedly, and finally "Dump HPROF file"
Save hprof file.
The following need to hprof file conversion.
Open CMD terminal, into the \ sdk \ platform-tools directory, use hprof-conv command to convert the file hprof
hprof-conv F: /a.hprof F: /b.hprof
Finally get b.hprof file.
To the official website: http: //www.eclipse.org/mat/downloads.php download Memory Analyzer tool.
Choose your version.
Open MemoryAnalyzer.exe, toolbar, select "File" -> "Open Heap Dump", select b.hprof
Overview selected in Action, click on the "Histogram"
You can search for the project name of the class, support partial match. I enter the Radar, a match the following content
Right One, select "Merge Shortest Paths to GC Roots" -> "exclude all phantom / weak / soft etc. references"
You can also use Overview The Dominator Tree to generate a new list, use Path again to GC Roots -> exclude weak / soft references screening procedures associated with memory leaks class.
Since ToastUtil is a utility class methods are static, and accept the Context parameter, this time passing in a activity in the Activity of context, leading to ToastUtil holds a reference to the activity while the activity is not released, the memory leak . The solution: a pass application context into account, let ToastUtil this context and have the same life cycle.
In addition, there will be Handler improper use of memory leaks, such as the use postDelayed in Handler.
Common solutions include the following:
1, the use of a static internal Handler / Runnable + weak references
2, onDestory when manually remove Message
3, third-party developers to use Badoo's WeakHandler