Almost every programmer encounters a memory leak in the process of development, so how do we detect where the app is going to have a memory leak? Square has unveiled a simple and crude tool for detecting memory leaks-leakcanary
What is a memory leak?
Memory leak refers to the failure of the program to release the memory that is no longer in use because of negligence or error, and the memory leak is not the physical disappearance of the internal, but the application allocates some memory, because the design error loses the control of this memory, resulting in a waste of memory.
Memory leaks and memory overflow is not the same thing, do not confuse, memory overflow popular is memory is not enough, now only mobile memory is more and more large, memory overflow situation is not many, but the memory leak situation is more serious, the arrival of Leakcanary for us is a simple rough, intuitive good tool
The above image is the icon of this tool, when your program is in debug mode, you can see him, of course, release no
Leakcanary as a simple and crude tool, the usage is quite simple.
Introduction of Leakcanary in Build.gradle
Debugcompile ' com.squareup.leakcanary:leakcanary-android:1.3 ' releasecompile ' com.squareup.leakcanary: leakcanary-android-no-op:1.3 '
One is the debug package, one is the release package, from the introduction of the structure of the package can also see the clues
Since leakcanary is testing the memory leak of the entire app, you need to start it in your application
Package Com.zimo.guo;import android.app.application;import com.squareup.leakcanary.leakcanary;/** * Created by Zimo on 15/8/7. */public class MyApplication extends application { @Override public void OnCreate () { super.oncreate (); Leakcanary.install (this);} }
OK, now you can test the memory leaks in the program, intuitive
So have the tool, hurry to try it, want to make your app's memory leaks, try it
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Leakcanary: Simple and crude memory leak detection Tool