Han Mengfei sha yue31313 Han Yafei Han_meng_fei_sha [email protected]
Leakcanary is square open source A memory leak automatic detection artifact. This is the project's GitHub warehouse address: Https://github.com/square/leakcanary. It is very easy to use a package dependency in Build.gradle:
dependencies { ' com.squareup.leakcanary:leakcanary-android:1.5' com.squareup.leakcanary:leakcanary-android-no-op:1.5' com.squareup.leakcanary:leakcanary-android-no-op:1.5 '}
Add initialization code to the OnCreate method in application:
if (leakcanary.isinanalyzerprocess (this)) {
This process was dedicated to leakcanary for
Heap analysis.
You should the NOT init your app on this process.
return;
}
Leakcanary.install (this);
After the integration of nothing to do, according to normal testing, when a memory leak occurs, the application will be notified through the system notification bar, click on the notification can be entered to view the details of the memory leak. Here is an example of a practice. After the leakcanary is integrated into the project, and so on after the app launches, the system notifies, clicks the notification, jumps to the leaked details page to view.
Android Memory leak tool Leakcanary use