Android 踩坑

FastgrabCongigReader 华为P9 内存泄漏

2017-09-23  本文已影响29人  jfson_土豆

最近有个泄漏很诡异,来自华为 P9

泄漏日志:

static android.rms.iaware.FastgrabCongigReader.mFastgrabCongigReader
references android.rms.iaware.FastgrabCongigReader.mContext
...

借用一张泄漏图:


imageimage

LoginActivity设置给了,导致LoginActivity被静态变量持有无法释放

public void fixMemoryLeak() {
        if (!"HUAWEI".equalsIgnoreCase(Build.MANUFACTURER)) {
            return;
        }

        try {
            Class<?> FastgrabConfigReaderClass = Class.forName("android.rms.iaware.FastgrabConfigReader");
            Field mFastgrabConfigReader = FastgrabConfigReaderClass.getDeclaredField("mFastgrabConfigReader");
            mFastgrabConfigReader.setAccessible(true);

            Object fastgrabConfigReader = mFastgrabConfigReader.get(FastgrabConfigReaderClass);
            Field contextField = FastgrabConfigReaderClass.getDeclaredField("mContext");
            contextField.setAccessible(true);

            if (contextField.get(fastgrabConfigReader) == this) {
                contextField.set(fastgrabConfigReader, null);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
上一篇下一篇

猜你喜欢

热点阅读