ADB dumpheap + MAT 分析内存泄漏

2023-10-18  本文已影响0人  河里的枇杷树

废话不多说直接说流程

  1. 通过adb dump 内存快照
adb shell am dumpheap {进程名} {存储路径} 

例如:
adb shell am dumpheap nova.priv.terminal.player.PlayService /sdcard/1.hprof
  1. 导出到电脑上
adb pull /sdcard/1.hprof C:\Users\...\1.hprof
转换mat标准文件
命令:hprof-conv -z src dst
例如:hprof-conv -z 1.hprof 1_mat.hprof
image.png
        InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        try {
            //获得 所有属性  getField->public  以及父类
            Field mCurRootViewField = InputMethodManager.class.getDeclaredField("mCurRootView");
            //设置允许访问权限
            mCurRootViewField.setAccessible(true);
            // 对象
            Object mCurRootView = mCurRootViewField.get(im);
            if (null != mCurRootView){
                Context context = ((View) mCurRootView).getContext();
                if (context == this){
                    //破怪gc 引用链
                    mCurRootViewField.set(im,null);
            }
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
上一篇 下一篇

猜你喜欢

热点阅读