4

We have an app that is jumping from 30-something MB of memory allocation to over 500MB while navigating between activities. I can track allocations while that happens, and see WHAT is being held in memory, but I want to create an HPROF file of the heap, so I can load it into MAT and get a better idea of what's using that memory.

However, when I try to create a dump, it just shows a dotted line and spinner on the memory graph, and that keeps up (seemingly) without end. I can create dumps with lower allocation without any issues, but with 500+ MB allocated, I cannot seem to do it.

I've looked for known issues with that scenario, but can't find any. Is there a setting I can change to help it along, or something I can do to troubleshoot the problem? Without a good analysis of the heap, I am blind as to what's happening with the memory.

Note: I'm not looking for help with the memory problem itself, ATM, I'm mostly interested in how I can get a heap dump to work.

jkane001
  • 1,694
  • 1
  • 15
  • 23
  • 1
    500MB should be well beyond the heap limit of your process, so I'm not sure how useful MAT will be. But, if there's a reliable way that you can get to the problematic state, write up a test case for it, and see if you have better luck getting an HPROF file [via `Debug.dumpHprofData()`](https://developer.android.com/reference/android/os/Debug.html#dumpHprofData(java.lang.String)). – CommonsWare Jan 07 '17 at 01:10
  • I'll give the terminal method a try, thanks! Unfortunately, there isn't a reliable way to reproduce the issue - we can use the app for days on end with no problem, and then suddenly see the spike, and once that's happened, only uninstalling and reinstalling will get it back to a working state. It's quite unusual. – jkane001 Jan 07 '17 at 01:15
  • @commonsware terminal command did the trick, thank you! If you submit that as an answer, I'll be happy to accept it. – jkane001 Jan 11 '17 at 22:29
  • I am not certain what terminal command you are referring to. I was referring to embedding `Debug.dumpHprofData()` in your Java code, to generate an HPROF file programmatically. You might want to answer the question yourself, to explain what you did that worked for you in your situation. – CommonsWare Jan 11 '17 at 22:31
  • 1
    I was looking for the solution to this problem for a co-worker, and in the same timeframe, he found this solution (http://stackoverflow.com/questions/19954420/how-to-automate-the-ddms-snapshot-mechanism), and did it. I didn't realize he'd used a different way to get the memory dump than I told him, so I misunderstood when he said the terminal approach worked. So, bottom line, there are (at least) 2 ways to get a memory dump other than via the "dump hprof" button in the Android Monitor. – jkane001 Jan 15 '17 at 19:01
  • Oh, hey, thanks for mentioning that! I hadn't realized that there was a command-line option for dumping the heap. – CommonsWare Jan 15 '17 at 19:12
  • @CommonsWare no problem - if you want to put what you said in an answer, I'll gladly accept it as the answer to my question. – jkane001 Jan 15 '17 at 22:39
  • 1
    Well, given what you used, I marked this as a duplicate of your actual solution. I am at a loss as to why this works where Android Studio does not, though, as both the command-line and the IDE should be using the `adb` interface to request the dump. – CommonsWare Jan 15 '17 at 22:41
  • Try increasing the amount of memory available to Android Studio: https://developer.android.com/studio/intro/studio-config.html#adjusting_heap_size – tmm1 Apr 03 '18 at 02:52

1 Answers1

0

I am sure this link will help you what you finding. I did through this way Here is the link :Memory Profiler

K P
  • 182
  • 9
  • I appreciate the link, it does have good info - but I already knew all that, my issue is that I can't get an HPROF file (as it recommends at the end of the article, to use MAT for in-depth profiling) to generate. – jkane001 Jan 07 '17 at 02:36