How to check Memory Leaks using Eclipse Memory Analyzer Tool (MAT) in Android App
Eclipse Memory Analyzer Tool (MAT)
Java handles its memory in two areas. The heap and the stack.
Java Heap
In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, e.g. by using the "new" operator. The Java garbage collector (gc) can logically separate the heap into different areas, so that the gc can faster identify objects which can get removed
The memory for new objects is allocated on the heap at run time. Instance variables live inside the object in which they are declared.
Java Stack
Stack is where the method invocations and the local variables are stored. If a method is called then its stack frame is put onto the top of the call stack. The stack frame holds the state of the method including which line of code is executing and the values of all local variables. The method at the top of the stack is always the current running method for that stack. Threads have their own call stack.
Install MAT on Eclipse
We need to install two eclipse plugins
1. BIRT Chart Engine //For Getting Memory Info with Pie Chart diagrams
2. MAT //For Getting Memory Info
——————————————————————————————
Install BIRT Chart Engine plugins
1. Eclipse —> Help Menu —> Install New Software —> Add
2. Enter below information
----------------------------------------------------------------------------
| Name : BIRT Chart Engine |
| Location: http://download.eclipse.org/birt/update-site/4.3 |
----------------------------------------------------------------------------
Source: http://wiki.eclipse.org/BIRT_Update_Site_URL
Now select only Birt Chart Engine and Go for Install.
——————————————————————————————
Install MAT plugins
1. Eclipse —> Help Menu —> Install New Software —> Add
2. Enter below information
----------------------------------------------------------------------------
| Name : MAT |
| Location: http://download.eclipse.org/mat/1.3/update-site/ |
----------------------------------------------------------------------------
Source:http://www.eclipse.org/mat/downloads.php
Now select MAT and Birt Chart Plugin for MAT and Go for Install.
——————————————————————————————
Get Heap Dump of Android Project
Once you installed ..
1. Connect Android Device for Debugging/Testing App
2. Now Go the The project and Build/Run
3. Open DDMS —> Devices —> Select Process (Project’s Package Name in List)
4. Click the "Dump HPROF File" icon in the Devices view's toolbar (looks like a half-filled can with a downward-pointing arrow)
5. Select the option Leak Suspects Report and click Finish.
6. That’s it!!.. You Got the App’s Memory Heap Report
——————————————————————————————
Analyse Memory Leaks, Allocation & GC etc.
Heap Overview
Few Important Links
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
http://2min2code.com/articles/eclipse_memory_analyzer/overview
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fgettingstarted%2Fbasictutorial.html
http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/
Java handles its memory in two areas. The heap and the stack.
Java Heap
In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, e.g. by using the "new" operator. The Java garbage collector (gc) can logically separate the heap into different areas, so that the gc can faster identify objects which can get removed
The memory for new objects is allocated on the heap at run time. Instance variables live inside the object in which they are declared.
Java Stack
Stack is where the method invocations and the local variables are stored. If a method is called then its stack frame is put onto the top of the call stack. The stack frame holds the state of the method including which line of code is executing and the values of all local variables. The method at the top of the stack is always the current running method for that stack. Threads have their own call stack.
Install MAT on Eclipse
We need to install two eclipse plugins
1. BIRT Chart Engine //For Getting Memory Info with Pie Chart diagrams
2. MAT //For Getting Memory Info
——————————————————————————————
Install BIRT Chart Engine plugins
1. Eclipse —> Help Menu —> Install New Software —> Add
2. Enter below information
----------------------------------------------------------------------------
| Name : BIRT Chart Engine |
| Location: http://download.eclipse.org/birt/update-site/4.3 |
----------------------------------------------------------------------------
Source: http://wiki.eclipse.org/BIRT_Update_Site_URL
Now select only Birt Chart Engine and Go for Install.
——————————————————————————————
Install MAT plugins
1. Eclipse —> Help Menu —> Install New Software —> Add
2. Enter below information
----------------------------------------------------------------------------
| Name : MAT |
| Location: http://download.eclipse.org/mat/1.3/update-site/ |
----------------------------------------------------------------------------
Source:http://www.eclipse.org/mat/downloads.php
Now select MAT and Birt Chart Plugin for MAT and Go for Install.
——————————————————————————————
Get Heap Dump of Android Project
Once you installed ..
1. Connect Android Device for Debugging/Testing App
2. Now Go the The project and Build/Run
3. Open DDMS —> Devices —> Select Process (Project’s Package Name in List)
4. Click the "Dump HPROF File" icon in the Devices view's toolbar (looks like a half-filled can with a downward-pointing arrow)
5. Select the option Leak Suspects Report and click Finish.
6. That’s it!!.. You Got the App’s Memory Heap Report
——————————————————————————————
Analyse Memory Leaks, Allocation & GC etc.
Heap Overview
Few Important Links
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
http://2min2code.com/articles/eclipse_memory_analyzer/overview
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fgettingstarted%2Fbasictutorial.html
http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/
Labels: android, Android Memory Leaks, Eclipse Memory Analyzer Tool, MAT
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home