//利用Application 可以监听Activity创建和销毁的功能,来捕获对应的Acivity的泄漏
AllocationTagLifecycleCallbacks.INSTANCE.register(getApplication(),NativeLeakTestActivity.this);
//开始循环监听(无力吐槽,代码结构太差)
LeakMonitor.INSTANCE.start();
nativeInstallMonitor(arr, arr2, monitorConfig.enableLocalSymbolic)
nativeSetMonitorThreshold(monitorConfig.monitorThreshold);
循环回调函数,size>0说明有native 层有泄露,会打印泄露大小等信息
@Override
public Boolean call() throws Exception {
Map<String, LeakRecord> map = new HashMap<String, LeakRecord>();
nativeGetLeakAllocs(map);
AllocationTagLifecycleCallbacks.INSTANCE.bindAllocationTag(map);
int size = map.size();
Log.e(TAG, "泄露个数:" + size);
if (size > 0) {
for (String key : map.keySet()) {
Log.e(TAG, "key: " + key + " value: " + map.get(key).toString());
}
}
LeakMonitorConfig config = (LeakMonitorConfig) monitorConfig;
LeakListener leakListener = config.getLeakListener();
return mIsStart;//false:循环遍历,不再监听泄漏信息
}
//创建navite层泄漏
NativeLeakTest.triggerLeak(new Object());