Card image cap

Table of Contents:



Introduction


In this blog post I'm going to talk about memory leak detection on Android.

I'm not going to talk about the topic of memory leaks in detail. This post is strictly focused on memory leak detection. If you want to know more about what memory leaks are, the most common ways they occur, and how to avoid them, check out my blog post: Memory Leaks on Android.


What is Leak Canary?


Leak Canary is an open source library developed by Square. It's extremely simple to set up and will allow you to very easily determine if your applications are leaking memory.


How Leak Canary Works


LeakCanary identifies objects that are no longer needed and finds the chain of references that prevents it from being garbage collected. If memory leaks are detected, Leak Canary builds a notification. You can click on the notification to see more information about the detected memory leaks.

If the notification is clicked, an activity opens that gives you an approximation of what objects are involved in the leak. You can then use that information to revise your code.


Setup


  1. Go to the Github page and add the dependencies to the build.gradle app file.



  2. Create a class that extends Application.


That's it...

Now when you run the application and go through the process that would normally create a memory leak, you'll get a notification with more information on the leak.

Note: Leak Canary is designed to help you determine where the memory leaks are occurring. Not how to resolve them. For information on how to resolve memory leaks check out my blog post: Memory Leaks on Android.


Staying in the Loop


If you want to stay in the loop and get an email when I write new blog posts, Follow me on Instagram or join the CodingWithMitch community on my website. It only takes about 30 seconds to register.





Authors


Mitch Tabian

codingwithmitch.com

Software Dev


Create an Account



Have an account? Log In

CodingWithMitch Members

Unlimited access to all courses and videos

Step by step guides to build real projects

Video downloads for offline viewing

Members can vote on what kind of content they want to see

Access to a private chat with other communnity members & Mitch

Become a Member

CodingWithMitch Members

Unlimited access to all courses and videos

Step by step guides to build real projects

Video downloads for offline viewing

Members can vote on what kind of content they want to see

Access to a private chat with other communnity members & Mitch

Become a Member

Comments