LeakCanary内存泄露检测工具报错 Dumping mem
报错信息:Dumping memory, app will freeze. Brrr
点击查看leaks小黄标,看到报错信息:
java.lang.UnsupportedOperationException: Could not find char array in java.lang.String@334750520 (0x13f3e338)
at com.squareup.leakcanary.HahaHelper.asString(HahaHelper.java:108)
at com.squareup.leakcanary.HeapAnalyzer.findLeakingReference(HeapAnalyzer.java:161)
at com.squareup.leakcanary.HeapAnalyzer.checkForLeak(HeapAnalyzer.java:115)
at com.squareup.leakcanary.internal.HeapAnalyzerService.onHandleIntent(HeapAnalyzerService.java:58)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
查看我本地的集成信息:
//leakcanary for memory leak
debugImplementation'com.squareup.leakcanary:leakcanary-android:1.5'
releaseImplementation'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testImplementation'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
原因是我leakcanary集成版本过低,推荐使用1.5.4或者1.6版本
//leakcanary for memory leak
debugImplementation'com.squareup.leakcanary:leakcanary-android:1.6'
releaseImplementation'com.squareup.leakcanary:leakcanary-android-no-op:1.6'
testImplementation'com.squareup.leakcanary:leakcanary-android-no-op:1.6'
修改以后重新运行,一切OK,能成功检测到内存泄漏。
编码不易:原文链接