基于内存优化工具leakcanary结合字节码插桩技术进一步高效识别内存泄漏问题

LC是个防止内存泄漏非常好用的工具,但LC自带只支持Activity,Fragment,ViewModel,RootView,Service对象的监控,如果想监控更多的对象,我们只能调用他的接口手动添加监控,这对于使用起来还是不太方便,因此,我尝试使用字节码插桩的方式,来自动监控更多的对象。

通过字节码的方式,支持以下:

java.io.Closeable#close

  • 文件流
  • Socket
  • Cursor
  • 其他继承Closeable

android.graphics.Bitmap#recycle

插桩工具:https://github.com/miqt/android-plugin/tree/master/plugin/inject-code-plugin

附录:
https://github.com/square/leakcanary/blob/main/leakcanary-object-watcher-android-core/src/main/java/leakcanary/AppWatcher.kt

猜你喜欢

转载自blog.csdn.net/qq_27512671/article/details/122958840
今日推荐