The GC collection mechanism is used when an object no longer holds any references.

Question: If an object is referenced by another object, it cannot be collected by GC?

Error. Because there are soft and weak reference objects, they can be reclaimed.

Correct. The object goes all the way back to the GC Root reference point before it can be collected by the GC.

Can be used as a GC Root reference point:

  • Objects referenced in the Java heap
  • The object to which a static reference in the method area points
  • The object to which the method area constant refers
  • Objects referenced by JNI in Native methods
  • Thread – A living Thread

Adb shell dumpsys meminfo package

AndroidStudio: the View – > Tool Windows – > Profile

When MAT is opened, you need to convert the hprof exported by AndroidStudio.

hprof-conv -z src/*.hprof dest

Compare the hprof of the two previous pages