Quote

"Between stimulus and response there is a space. In that space is our power to choose our response.
In our response lies our growth and freedom"


“The only way to discover the limits of the possible is to go beyond them into the impossible.”


Monday, 24 February 2014

Memory Analysis Using Eclipse Memory Analyser Tool



The Eclipse Memory Analyzer is a tool for Java heap analysis to help find memory leaks and help perform analysis for reduction of memory consumption.

It can be used to analyze heap dumps with hundreds of millions of objects and quickly calculate the retained sizes of objects. It can be used to analyze what is preventing the Garbage Collector from collecting objects, generate a report to automatically extract leak suspects.

Before starting the analysis it is important to have a clear understanding of the following terms related to memory management in the context of java:

Memory manger
Memory pool
Heap memory
Non-heap memory
Garbage collection
Heap dump

Memory manager are used to manage one or more memory pools. For example the garbage collector is a type of memory manager used to reclaim memory used by unused objects. A Java VM may have one or multiple memory managers which can be added or removed at run time.

Memory pool is memory area managed by the Java VM. At runtime at least one memory pool is present and the number of memory pools can vary during execution. Memory pools can be associated to either heap or to non-heap memory and it can be managed by more than one memory managers.

Heap memory is the memory area from which the allocation is done for all instances and classes at the runtime. The size of the heap can be of a fixed or made variable. The garbage collector is an automatic memory management system that reclaims heap memory for objects.

Non-heap memory is a collection of method area that is shared among all threads and the memory that is needed for the internal processing /optimization of the Java VM. Like the heap memory, the method area may be of a fixed or variable size. The memory for the method area does not need to be contiguous.

Garbage collection (GC) is the method used by the Java VM to free memory used by objects that are no longer being used. The objects that have active references as can be called alive and the objects which do not have any reference can be presumed dead. So the process of releasing memory used by the dead objects is called Garbage Collection (GC).

Heap dump is a snapshot of the complete Java object graph at a certain point in time which is stored in a binary format called HPROF.

Generation of Heap Dump: Depending on the operating system you can instruct the JVM to automatically create a heap dump when it runs out of memory. To create a heap dump automatically in case of out of memory error start the Java application with the following argument-XX:+HeapDumpOnOutOfMemoryError . Heap dump is by default generated in the working directory of the VM but it is also be generated at specified path by using the –XX:HeapDumpPath=<PATH>. Heap dump can also be generated on demand by using tools like JMap and JConsole.

Installing Memory Analyzer Tool (MAT) on Eclipse
To use eclipse memory analyzer tool we need to install couple of plug-ins which will help analyze the heap dumps and generate useful reports out of it. 

We need to install the following plugins:

The steps to install MAT and BIRT chart engine are similar so the steps by step installation for newbie’s is as follows:


  • Click Help --> Install New Software

 
  • Select Memory Analyzer for Eclipse and Stand-alone Memory analyzer and click Next
 
  • Click Next and accept the license agreement

  • Restart eclipse and Memory analyzer is ready to use



In the next post I will be taking up:

  • Generation of heap dump using MAT
  • Running memory leak suspect report using MAT

No comments:

Post a Comment