Downloaded a project on github: Installing the debug version will generate two apks, one is the apk itself, and the other is Leaks
The release version is normal and will not cause this problem. I am puzzled and this is the first time I have encountered this problem.
After seeing this blog, it suddenly became clear: there are the following configurations in build.gradle.kts:
// memory leak analysis debugImplementation("com.squareup.leakcanary:leakcanary-android:2.10")
When the installation package is a debug package, Leakcanary will run automatically. If there is a memory leak, there will be a prompt on the page. Click the Leaks icon on the desktop to see the details of the memory leak, and it will display which Acitivity has leaked
Preface:
In software development, memory is the most troublesome thing . Sometimes OOM errors will be reported if a few problems are not well grasped, so I recommend a method for monitoring OOM.
Usage:
1. gradle :
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
}
2、Application -> onCreate:
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
3. Run the program, (an application of leaks will be generated on the desktop, and the log of memory overflow is recorded here). When the program exits or exits a certain interface, if there is memory overflow, it will automatically pop up a prompt or you can also Go to leaks to see. Be careful to cancel this function when publishing the application!
The effect is as shown in the figure:
4. For details, please go to the official website: https://github.com/square/leakcanary ;
Q: https://github.com/square/leakcanary/wiki/FAQ
Ps: This can only be tested when the version is Debug, and it will be canceled when the official version is released.
When I tested it myself, it didn't work if the phone became hot after opening a few pages. Or open the application and leave it there, it will start to get hot after a while, occupying too much CPU and consuming a lot of electricity. If you have friends who have used it, welcome to communicate.