LeakCanary: simple and crude memory leak detection tool, leakcanary Leak Detection

Source: Internet
Author: User

LeakCanary: simple and crude memory leak detection tool, leakcanary Leak Detection

Almost every programmer may experience memory leakage during development. How can we detect memory leakage in the app? Square introduces LeakCanary, a simple and crude tool for detecting memory leaks.

What is memory leakage?

Memory leakage refers to the failure of the program to release memory that is no longer in use due to negligence or errors. Memory leakage does not mean that the internal memory disappears physically, but after the application allocates a certain segment of memory, due to the design error, the control of the memory segment is lost, resulting in a waste of memory.

Memory leakage and memory overflow are two different things. Do not confuse them. In general, memory overflow is not enough. Currently, only the mobile phone memory is getting larger and larger, and there are not many memory overflow situations, however, the memory leakage is serious. LeakCanary is a simple, rough, and intuitive tool for us.


The figure above is the icon of this tool. When your program is in debug mode, you can see it. Of course, release does not


LeakCanary is a simple and crude tool, and its usage is quite simple.

Introduce 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 and the other is the release package. It can be seen from the structure of the introduced package.

Because LeakCanary is used to test the memory leakage 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 we can test the memory leakage in the program, which is intuitive and clear.


This is a powerful tool. Please try it out. If you want to make your app memory leak, try it.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.