Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if my android app has memory leak?

Tags:

I look all over the internet\goolge\stackoverflow and couldn't find full and simple guide that can explain to me how can I find if my android app has a memory leak. Can anyone explain to me how to do it, or even better give me good guide for it?

My app collecting data about the battery and saves it to DB on the phone. Each time that their is a change in the battery (ACTION_BATTERY_CHANGED) I check if the battery precentage changed and in this case I save some data.

This app takes (25-30)MB RAM I think that this is too much for such simple app.I suspect that it has a memory leak.

like image 242
Alex Kapustian Avatar asked Jun 16 '12 15:06

Alex Kapustian


People also ask

How do I know if my app has a memory leak?

An obvious first step is to check if your app ever crashes due to OutOfMemoryError. Unless there's a single screen that eats more memory than your phone has available, you have a memory leak somewhere. This approach only tells you the existence of the problem—not the root cause.

How do you identify a memory leak?

The system can have a myriad of symptoms that point to a leak, though: decreased performance, a slowdown plus the inability to open additional programs, or it may freeze up completely.

What is app memory leak?

Memory leaks occur when an object that is supposed to be garbage collected has something holding a reference to it. As more and more instances of that object are created, older instances are still being retained in the application's memory.


2 Answers

You can use MAT

It is a very good tool and gives very detailed report of your project with basic information linked with memory leaks

MAT in Android

http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html

How to use MAT

http://kohlerm.blogspot.in/2009/07/eclipse-memory-analyzer-10-useful.html

http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html

http://ttlnews.blogspot.in/2010/01/attacking-memory-problems-on-android.html

Eclipse integration of MAT

http://www.eclipse.org/mat/downloads.php

http://www.eclipse.org/forums/index.php/m/878338/

Update Site: http://download.eclipse.org/mat/1.1/update-site/

Eclipse integration of BERT (dependency on this )

http://wiki.eclipse.org/BIRT_Update_Site_URL

http://download.eclipse.org/birt/update-site/3.7-interim

Memory Analyzer Tool in android?

like image 146
Dheeresh Singh Avatar answered Oct 01 '22 16:10

Dheeresh Singh


When I faced the same problem as you, I found LeakCanary. It helps to detect memory leaks during runtime in debug builds and provides comfortable UI for the stacktrace history. Here you can read more information about this tool for detecting memory leaks as well as some other useful hints for Android development: http://cases.azoft.com/4-must-know-tools-for-effective-android-development/. Hope it works for you and other mobile developers!

like image 31
Vladimir Tchernitski Avatar answered Oct 01 '22 18:10

Vladimir Tchernitski