通过MonitoSDK的Sample App进行试用时,发现存在部分内存泄漏的情况,leakcanary直接弹出提示如下
可以看到MonitorDBActivity的instance导致泄漏。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_db); ButterKnife.bind(this); } @OnClick(R.id.inputData) public void inputData() { EditText input = (EditText) findViewById(R.id.inputTestData); int num = Integer.valueOf(input.getEditableText().toString()); ErrorReporter reporter = ACRA.getErrorReporter(); CrashReportDataFactory factory = null; try { factory = Reflect.on(reporter).get("crashReportDataFactory"); } catch (ReflectException e) { e.printStackTrace(); } for (int i = 0; i < num; i++) { final ReportBuilder builder = new ReportBuilder(); builder.exception(new Exception(i + "")); final CrashReportData crashReportData = factory.createCrashData(builder); MLog log = null; try { log = new MLog(crashReportData.toJSON().toString()); } catch (JSONReportBuilder.JSONReportException e) { e.printStackTrace(); } MLogStoreMgr.getInstance(this).add(log); } }