Android 内存泄漏检测

   内存泄露检测对于我个人而言,是对我自己写的代码一次检查,可以检查代码哪些地方写得不对或者错误。

leakcanary 比较好用,git官网:https://github.com/square/leakcanary

  1.在app build.gradle添加dependencies

    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'

 2.在applocation 里添加代码

     private void leakCanary(){

       if (LeakCanary.isInAnalyzerProcess(this)) {

      // This process is dedicated to LeakCanary for heap analysis. // You should not init your app in this process.

       return; }               

   LeakCanary.install(this);

3.接着run自己app就行,把自己的app安装到测试手机上全部页面跑一下,多操作几次,

   内存溢出信息会以通知的形式展示在通知栏上,再逐条更改。

 

内存溢出情景:(长期添加)

1.设置的静态变量,导致内存溢出。

   在a  activity里写了一个静态变量,在b中调用,导致的内存泄漏。android变量的保存可以通过sp和application

   来暂时存储,可以避免发送内存泄露。

 

 

 

 

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值