0

I am trying to see which objects take most of the memory in my app.
Using Android's studio Android->Memory tab I can see how the memory increases but I can't see which objects occupy how much memory.
I used DDMS to get an hprof and also did a start alocation tracking and "Dump Java Heap" from the Memory tab.
I installed the standalone mat but when I try to open the hprofs I get for both:

Error opening heap dump 'Snapshot_2016.01.08_19.00.05.hprof'. Check the error log for further details.

What is the problem?
My version of Android Studio is 1.3.2

Jim
  • 18,826
  • 34
  • 135
  • 254

1 Answers1

2

Using Android's studio Android->Memory tab I can see how the memory increases but I can't see which objects occupy how much memory

You can generate a heap dump on Android Studio, from the toolbar in that Memory tab. That will open up tools, akin to MAT, for you to peruse what objects are in memory.

Android Studio 1.5.1, Showing Heap Dump

Error opening heap dump 'Snapshot_2016.01.08_19.00.05.hprof'. Check the error log for further details.

The heap dump format that Android uses is slightly different than the one MAT uses. There is an hprof-conv tool in platform-tools/ of your Android SDK that can prepare a MAT-friendly edition of the .hprof file.

The documentation has a bit of material on this.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • When I press the icon "Dump java heap dump for selected client" it saves the hprof in a folder. What tools should I use to open it? – Jim Jan 08 '16 at 21:19
  • @Jim: Off the cuff, it feels like you have an older version of Android Studio. The tooltip on that icon in AS 1.5.1 is "Dump Java Heap", and it automatically opens up the heap dump in Android Studio itself, as shown in the screenshot in the answer. – CommonsWare Jan 08 '16 at 21:21
  • Using the hprof-conv I was able to open the hprof using mat. So does this mean that in versions before 1.5.1 mat is the only option? – Jim Jan 08 '16 at 21:27
  • @Jim: The in-Studio heap viewer is fairly new. I forget whether it was introduced in 1.4 or 1.5. – CommonsWare Jan 08 '16 at 21:36
  • So generally is Android Studio becoming more useful than mat on analysis? Or it is just a convenient first step to check? – Jim Jan 08 '16 at 21:38
  • @Jim: There may be some things in MAT that the Android Studio heap viewer lacks. For basic stuff, if you could do it in MAT, you can do it in Studio, and Studio has a couple of tricks that MAT lacks (e.g., checking some Android-specific stuff like leaked activities). – CommonsWare Jan 08 '16 at 21:42