HomeWorld Tech

How to analyze memory using android studio –

How to analyze memory using android studio –
Like Tweet Pin it Share Email

Development issue/problem:

Recently switched from eclipse to android studio. How to check a set of applications and memory allocation in android studio? In Eclipse we have MAT, is there anything in Studio to check the reset stack, the hprof file?

How can I solve this problem?

Solution 1:

I explain it very simply in steps:

  1. You must install (download) or use the MAT first:

Storage analyser for installation in a vessel

  1. In Android Studio, open the Android Device Monitor or DDMS.
  2. Select your process com.example.etc.
  3. Click on the Refresh Heap button above the process list.
  4. Select the Bag tab in the right sidebar.
  5. Click on GC Reason.
  6. Click Empty HPROF file above the process list.
  7. Once we have downloaded the HPROF file, we need to open a terminal and execute this command to create the file and open it with MAT.
  8. Open a terminal and execute this command

./hprof-conv path/file.hprof exitPath/heap-converted.hprof

The hprof-conv command is located in the platform-tools folder of sdk.

  1. Now the MAT can open and display the converted file ( heap-converted.hprof ).

Solution 2:

There’s another way to look at the mission:

Starting and stopping the monitoring of commands

View the result

Solution 3:

Android Monitor -> Monitors (in addition to the log code) -> Memory -> Reset Java Heap

Give here a description of the image

Solution 4:

I agree with the above answer, with the exception of the following steps.

  1. Click on the Refresh Heap button above the process list.
  2. Select the Bag tab in the right sidebar.
  3. Click on GC Reason.

Select your application/process in DDMS and click the HPROF profile dump option. Then follow the steps above.

Solution No 5:

You can also do the following to get more options,

  1. Go to tools
  2. Then to Android.
  3. finally on the Android device monitor

Solution No 6:

  1. Install MAT first, to use it in Android Studio, you need to install the Standalone Eclipse RCP Applications option, which can be used as a standalone tool.
  2. Launch your application in Android Studio
  3. In the lower sidebar, select 6: Android, then select Memory Monitor
  4. Click on Dump Java Heap
  5. Click on the Captures tab (on the left side of the bar) and search for the .hfp file in the Heap Snapshot folder.
  6. To open a .hprof file in MAT, you need to open the :
    Left click on the .hprof file and select Export to default .hprof.
  7. Open MAT, and then the .hprof file you created in

Solution No 7:

Note that in the latest Android Studio (1.3+), heap capture (Android hprof) has been moved to the Memory Monitor sub-tab under the Android tab (like the first frame in cVoronin’s response).

When the recording is finished, it is automatically saved in the Captures directory of your project (you can rename the file as you wish). The hprof file is automatically opened in the new version 1.3+ of hprof viewer.

Of course you still have the possibility to convert them to the standard hprof format and display them in MAT. Right-click the file in the Capture Browser (under the Project Browser) and select Convert. And as usual you will lose additional Android-specific information if you don’t use the new viewer, as the standard hprof doesn’t support it.

Solution No 8:

I switched from Eclipse to Android Studio, but I still use MAT in Eclipse, with the DDMS plugin. It’s a lot easier.

Solution No 9:

I know it’s a pretty old question, but Android Studio 3 now has a built-in profiler.

See the documentation here: Profiler for Android in Android Studio 3.0

Solution No 10:

You can use the android profiler in the new android studio.