Git Product home page Git Product logo

simpleleakcanary's Introduction

SimpleLeakCanary

LeakCanary simple version

抽取了LeakCanary检测部分的代码,放在了这里,有兴趣的可以看下
原理简单点说就是: 在onDestroy的时候为Activity加上WeakReference,然后在合适的时机调用Runtime.getRuntime().gc()触发GC,之后检测下WeakReference还是否存在。
如果存在,那么Activity就泄露了;如果不存在,那么表示回收正常。
具体的细节部分请看抽取代码。
RefWatcher是引用监听,也是监听部分最核心的代码。

LeakCanary源码工程导读

  • leakcanary-analyzer : 如果检测到内存泄露,就dump出hprof分析,这个库主要用于分析hprof。 代码利用了MAT
  • leakcanary-android-no-op : 空实现,为了方便在release时调用
  • leakcanary-android : debug时调用,组织监听、分析、展示结果等逻辑。
  • leakcanary-sample : 官方调用示例
  • leakcanary-watcher : 引用监听

声明

本库只是将LeakCanary监听部分做了简化处理,方便大家以最小的成本学习原理。
源码中还包含了排除SDK本身泄漏的部分,本库没有包含进来,开发中还请使用LeakCanary。

simpleleakcanary's People

Contributors

gavinct avatar

Watchers

wuyuzhou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.