Taruni
Taruni

Reputation: 1671

Memory Analyzer Tool in android?

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.

Upvotes: 22

Views: 23092

Answers (7)

ubuntudroid
ubuntudroid

Reputation: 3999

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.

Upvotes: 0

Dong Thang
Dong Thang

Reputation: 418

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.

Upvotes: -2

daimajia
daimajia

Reputation: 967

Square open sourced a memory analysis tool: LeakCanary.

The core of the LeakCanary is MAT.

Upvotes: 0

Stephen
Stephen

Reputation: 10079

  • 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.

Upvotes: 0

Ramya K Sharma
Ramya K Sharma

Reputation: 743

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

Upvotes: 1

Michael
Michael

Reputation: 54725

  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.

Upvotes: 23

Related Questions