| By Pavan Kumar Gorakavi | Article Rating: |
|
| December 25, 2009 02:45 PM EST | Reads: |
10,936 |
The garbage collector is primarily responsible as a collector to reclaim objects that are no longer used by the application. This is an automatic memory management invented by McCarthy. The garbage collector collects unreferenced objects, objects that are not reached by the reference chain. The starting point of the analysis is the Garbage Collection Root (GCR), which are objects that are reachable by the VM. Objects that are nonreachable are garbage collected, whereas objects that are reachable are sustained in memory. GCR is very useful in identifying memory leaks and the reference chain from an arbitrary object to GCR tells about the suspects.
The Eclipse Memory Analyzer is a fast, feature-rich Java heap analyzer that helps to identify memory leakage. This project was initially released in December 2008 and is now part of the Galileo release train. The Eclipse Memory Analyzer (MAT) provides a large selection of features to help in analyzing a single snapshot of heap. MAT can be used to identify memory leaks using a single click.
Heap Dump - Shallow Heap, Retained Heap
HPROF heap dump is a snapshot of a Java heap at a particular instance in time. The garbage collector is triggered before the dump is written. It contains information about all objects, all classes, GCR, and all information about the remaining objects. Heap does not contain allocation information. Shallow heap is the memory consumed by one object at that instance. Retained Heap is the sum of the shallow sizes of all objects in the retained set.
Leak Suspect Report with a Single Click
Acquire heap dumps
Heap dump can be obtained either by on-demand or by an out of memory error. In the Sun JVM 1.4.2_12 or after, we can get a heap dump on out-of-memory by using the following JVM parameter
-XX:+HeapDumpOnOutOfMemoryError
An on-demand heap dump can be obtained using the following JVM parameter:
-XX:+HeapDumpOnCtrlBreak
We can also get the heap dump using jmap, jconsole, and hprof.
Importing an hprof file
Open the downloaded hprof file into your workspace. Click on File -> Open Heap Dump and give the hprof file reference.

Once a file is opened, MAT process the hprof file. Check your heap restraints while processing huge hprof files. You can extend the heap configurations at MemoryAnalyzer.ini. Once parsing completes, we need to select a leak suspect report to check heap dump for leak suspects. It provides details about the different objects and why they have not been garbage collected.

We get a higher level of leak suspect report with a pie chart and list of leak suspects.


To get the top consumer at that particular instance, we need to click on Top Consumer in the Leak Identification Category.

The denominator tree lists the biggest objects. It's also called as a keep-alive tree as the next level shows those objects that are immediately prevented from garbage collections.
By drilling down, we can check incoming - outgoing references, GCR. The dominator tree can also be grouped by class loaders. The histogram view lists the objects grouped by class.
This view helps to identify the starting point for our analysis. Asample histogram view is illustrated below.

OQL Editor
MAT allows you to query the heap dump using SQL-like queries. OQL represent classes as tables, objects as rows, and fields as columns.
SELECT *
FROM [ INSTANCEOF ] <class name="name">
[ WHERE <filter-expression> ]
</filter-expression></class>

Conclusion
The Eclipse Memory analyzer provides a good offline analysis of a snapshot. I prefer to use both offline and online profilers to make sure my application is leak-proof.
Reference
Published December 25, 2009 Reads 10,936
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Pavan Kumar Gorakavi
Pavan Kumar Gorakavi is currently working as senior software developer in Dallas, TX. He is also acting as vice president for IPMA - Young Crew, USA.
- Asynchronous Logging Using Spring
- What to Expect in 2012: Cloud Computing and Open Source Software
- Will PaaS Finally Bring Open Source Love to the Enterprise?
- AT&T Joins OpenStack, Floats Cloud Architect
- Red Hat Sets Up GlusterFS Advisory Board
- Linux Virtualization and Tired Open Source Myths
- OpenOffice.com Lives
- Acquia Announces Two New Board Members
- Cloud Computing: A Platform-First Approach
- Powering the Cloud with Open Source
- Top 10 Open Source eCommerce Software (Joomla and Drupal)
- Piston Delivers First OpenStack-Based Cloud OS
- Adobe Sends Flex to the Apache Foundation
- i-Technology in 2012: Five Industry Predictions
- Microsoft Tries Hadoop on Azure
- OpenXava 4.3: Rapid Java Web Development
- Asynchronous Logging Using Spring
- StorSimple Supports OpenStack
- What to Expect in 2012: Cloud Computing and Open Source Software
- Will PaaS Finally Bring Open Source Love to the Enterprise?
- AT&T Joins OpenStack, Floats Cloud Architect
- More Use Cases for Big Data Analytics
- Red Hat Sets Up GlusterFS Advisory Board
- Linux Virtualization and Tired Open Source Myths
- After Ubuntu, Windows Looks Increasingly Bad, Increasingly Archaic, Increasingly Unfriendly
- SCO CEO Posts Open Letter to the Open Source Community
- Simula Labs Launches Hosted Delivery Platform To Enable Enterprise Open Source Adoption
- Where Are RIA Technologies Headed in 2008?
- Source Claims SCO Will Sue Google
- How Open Is "Open"? – Industry Luminaries Join the Debate
- Latest SCO News is Plain Weird
- SCO Claims Linux Lifted ELF
- IBM Tells SCO Court It Can't Find AIX-on-Power Code
- Flashback: Investing in 'Professional Open Source' - Exclusive 2004 Interview with David Skok, Matrix Partners
- Developing an Application Using the Eclipse BIRT Report Engine API
- HP Starts Pushing Desktop Linux




















