安卓内存问题---解决内存溢出

最近几天,发现APP OOM了,惊出一身冷汗有没有。。。

网上一查,studio可以检查内存,果断走起


运行APP,切换界面,发现APP内存不断上涨。泄露有木有。要加班的节奏啊

新版的studio,确实很强大,可以检测内存泄露问题,

步骤:

概念:内存泄露就是说:退出界面,本该通过GC回收的,因为存在某种引用而不能回收。运行studio会发现,当切换某个界面的时候,内存不会降到原来水平,一直有残留,这肯定有泄漏了。

反复的点击切换有泄漏的界面,。点击dump java heap 按键,studio就开始工作了


结束后会生成prof文件,打开


内存情况一目了然。但还是不大只能,后来使用的

LeakCanary

很简单好用

GitHub地址:https://github.com/square/leakcanary

In your build.gradle:

 dependencies {
   debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
   releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
   testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
 }

In your Application class:

public class ExampleApplication extends Application {

  @Override public void onCreate() {
    super.onCreate();
    LeakCanary.install(this);
  }
}
就可以了,安装点击切换界面,会自动检测泄漏问题,然后一点点处理吧。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值