22

I just want to know how to work with Memory analyzer tool in android. Please tell me how to do this to know about memory leaks for a particular project. Can someone give me step wise procedure for this.

7 Answers 7

23
  1. Open DDMS perspective in Eclipse.
  2. Select Devices tab.
  3. Choose a process you want to make a dump for.
  4. Click Dump HPROF file button. The dump will be made and MAT window will be opened, assuming MAT is installed.
  5. Choose Leak Suspects Report in the wizard window and click Finish.

That's all. You'll se a list of possible leaks, but some of them are false-positive. I recommend you to run an activity you want to check leaks in several times and then run MAT again.

9
  • 1
    Thank You,let me check it out......Actually i want to know memory leak for a particular project or activity how would i load a particular project for memory leak
    – Taruni
    May 21, 2011 at 9:57
  • 3.Choose a process you want to make a dump for...what is the process here...i didnt get
    – Taruni
    May 21, 2011 at 10:02
  • I hope you don't have thousands of leaks so it will not be so difficult to find all leaks for a particular object. But I don't think MAT has such a feature to search leaks of some objects. It just searches all possible leaks.
    – Michael
    May 21, 2011 at 20:38
  • 1
    When you open the Devices tab in the DDMS perspective, you'll see a list of devices and for every device there will be a list of processes that are launched on this device. One of this processes will be your application's process. It has a name equal to a package name of your application. Select this process and follow the next step.
    – Michael
    May 21, 2011 at 20:41
  • Hey thanks for ur reply...when i clicked the Dump hprof file i am getting the following error::: hprof: can't open /sdcard/profileit.ImageDemo.hprof-hptemp: Permission denied.
    – Taruni
    May 23, 2011 at 3:59
4

Try Using the Memory Analyzer Tool (MAT)

Look at these articles:

Also look at these SO Posts:

3
  • Thank You,let me check it out
    – Taruni
    May 21, 2011 at 9:56
  • Actually i want to know memory leak for a particular project or activity how would i load a particular project for memory leak
    – Taruni
    May 21, 2011 at 9:59
  • while using DDMS mode i am getting the following error::: hprof: can't open /sdcard/profileit.ImageDemo.hprof-hptemp: Permission denied.
    – Taruni
    May 21, 2011 at 10:07
1

Write to hprof fails when you have not used android.permission.WRITE_EXTERNAL_STORAGE. As a special case when you are testing on device, check if your SD card is connected in Charge ONLY mode otherwise you wont have write access on SD Card

0
0
  • Install MAT.

  • Go to Tools->Android ->Android device monitor(DDMS)

  • In the top left side under Devices,select the project name and click Update Heap.

  • Then Click Dump HPROF File and saved it in desktop.

  • Then run the Command prompt and point out the Android-sdk directory.

    For an Example: hprof-conv is located in E directory. So run the command as cd android/sdk/platform-tools.

  • Then finally run this command by referring this doc to convert this file format to read it in MAT.

    E:\Android\sdk\platform-tools> hprof-conv "C:\Users\Steve\Desktop\yourfilename.hprof" "C:\Users\Steve\Desktop\leakage.hprof"

  • Now your file will converted to leakage.hprof.check this file and open it in MAT.

Edit: Click details,then it will show the class names.In that Left Click -> Path To GC Roots ->With all references.Then it shows the class name.

0

Square open sourced a memory analysis tool: LeakCanary.

The core of the LeakCanary is MAT.

0

I'd recommend taking a look at Leak Canary. It's not a memory analyzer per se, but more a leak detector. Just use your app, open and close activities and let the library do it's job. It will even tell you about where the leak occured. Just give the leak analyzer some time to do its work after the leak occured - it usually takes around 2 minutes or more until the source of the leak has been found.

-2

Please update to Android studio version 1.4 or 1.5. In this version, android has supported new tool its called Analyzer Task It is very useful to avoid memory leak.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.