1. Avoid controlled memory leaks

1.1 What is a Memory leak

1.2 Memory Leakage Scenario

1.2.1 Static instances of non-static inner classes

1.2.2 Multithreaded anonymous inner Classes/non-static inner classes

1.2.3 Handler Memory Leaks

1.2.4 Incorrect Use of Context

1.2.5 static View

1.2.6 WebView

Using a WebView loads the APK resources of the WebView and is not unloaded until the end of the application life cycle.

Does Android WebView still have memory leaks?

1.2.7 Resource Objects Are Not Closed

1.2.8 Objects in the Collection are not cleaned

1.2.9 Bitmap object

1.2.10 Listeners Are not closed

2. Memory Monitor

2.1 Using Memory Monitor

2.2 Large Memory Application and GC

2.3 Memory Jitter

3. Allocation Tracker

3.1 Using the Allocation Tracker

3.2 Alloc file analysis

4. Heap Dump

4.1 Using Heap Dump

4.1.1 Overview View

4.1.2 Detailed View

4.2 Detecting Memory Leaks

5. Memory analysis tool MAT

5.1 Generating the Hprof File

5.1.1 Preparing code for memory leaks

5.1.2 DDMS Generates the Hprof file

5.1.3 Memory Monitor generates hprof files

5.2 MAT analyzes the Hprof file

5.2.1 Dominator Tree

A Dominator Tree is a dominant Tree.

  • Shallow Heap
  • Retained Heap

5.2.2 Histogram

5.2.3 requires OQL

OQL is a Query Language similar to SQL. It is used to Query all objects that meet specified conditions in the memory.

5.2.4 Comparing Hprof Files

6. LeakCanary

Github.com/square/leak…

6.1 use LeakCanary

Look at the official documentation.

6.2 LeakCanary Application Example

Take a look at the official documentation for an example from some years.

  • RefWatcher