2.7版本监控对象:
activity
fragment
viewmodel(自己创建一个viewmodle,在clear的时候hook获取ViewModelStore里面的mMap,就可以获取viewmodel进行检测。
view(hook windowmanagerglobal的mviews,替换为自己的arraylist,在add函数在addOnAttachStateChangeListener,触发onViewDetachedFromWindow的时候检测。
sevice(hook activitythread的mcallback)
fun appDefaultWatchers(
application: Application,
reachabilityWatcher: ReachabilityWatcher = objectWatcher
): List<InstallableWatcher> {
return listOf(
ActivityWatcher(application, reachabilityWatcher),
FragmentAndViewModelWatcher(application, reachabilityWatcher),
RootViewWatcher(reachabilityWatcher),
ServiceWatcher(reachabilityWatcher)
)
}
触发gc
override fun runGc() {
// Code taken from AOSP FinalizationTest:
// https://android.googlesource.com/platform/libcore/+/master/support/src/test/java/libcore/
// java/lang/ref/FinalizationTester.java
// System.gc() does not garbage collect every time. Runtime.gc() is
// more likely to perform a gc.
Runtime.getRuntime().gc()
enqueueReferences()
System.runFinalization()
}
dump
Debug.dumpHprofData(heapDumpFile.absolutePath)
Analysis,采用shake
heapAnalyzer.analyze()
网友评论