美文网首页
检测内存泄漏、优化的常用手法[笔记]

检测内存泄漏、优化的常用手法[笔记]

作者: 吉凶以情迁 | 来源:发表于2021-12-02 10:43 被阅读0次
    • 可视化自动内存泄漏检测
    //    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3' ///屏蔽提升操作速度,开启后不需要任何代码的。 原理是内容提供者
        
    
    • 开启自带的检测
    if(BuildConfig.DEBUG){
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
    //                    .detectLeakedSqlLiteObjects()
    .detectFileUriExposure()
    .detectActivityLeaks()
    .detectLeakedClosableObjects()
    .detectLeakedRegistrationObjects()
    .detectLeakedSqlLiteObjects()
    //                    .detectLeakedClosableObjects()
    //                    .detectAll()
    .penaltyLog()
    .penaltyDropBox()
    .build());
    }
    
    • Android Studio Profiler检测

    一个APP通常只分配256 或者512大小的内存,查看自己应用使用了多少,

    比较麻烦的还有很多,官网可查,目前这个是比较方便的。

    • 测试
    
    adb shell monkey  -p com.sotrun.app --throttle 380 -v -s 3500 300000 >C:\monkey_log.txt
    停止方法
    ps -A|grep monkey
    kill -9 
    

    更高级的需要写代码测试,比较麻烦。

    相关文章

      网友评论

          本文标题:检测内存泄漏、优化的常用手法[笔记]

          本文链接:https://www.haomeiwen.com/subject/imjyxrtx.html