18

I am new to this Android platform. In one application, there is a memory leak but I couldn't find in which activity or class the memory leak is happening.

I am using MAT to get the information that the memory leak is there or not but I am not able to find which activity is leaking.

Please tell me how to find which activity is leaking.

2

6 Answers 6

35

Even if this question is quiet old. I think a small tutorial with images might be helpful. So first you need to install the MAT plugin. After a restart click on Dump HPROF file:

Device controls

After some time (about 30 seconds) you'll get a dialog where you can click on finish. Than you get this view:

Dump result

There you left click on the biggest part and filter for with outgoing references. Then you get this view here:

Here you can see that I missed to delete items in my ContentManager where several items were stored in my pending HashMap.

Sign up to request clarification or add additional context in comments.

Comments

5

The best post I found yet on tracking memory leaks on android platforms is:

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

The first part is outdated because it's now integrated into Eclipse but most of the post is great!

Comments

4

Use LeakCanary - a memory leak detection library for Android and Java. LeakCanary will automatically show a notification when an activity memory leak is detected in your debug build. Installing this library is very simple.

https://github.com/square/leakcanary

Notification example:

enter image description here

Comments

2

I can't comment on the previous post, but it's important to realise that you absolutely should worry about memory management, especially on the resource-confined environment that is the Android mobile platform. For more on that, check here:

http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

1 Comment

Avoidance can only get you so far. Sometimes it's a third party library that trips up your code.
0

You can see it in the DDMS.

Simply select your app package name and click update heap the above button.

Now goto Heap Tab click Cause GC.

you will find the listing of objects used.

Comments

0

You can analysis android memory leaks automatically with MMAT,MMAT github page

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.