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

Tuesday 11 February 2014

Create personalized letters for large groups using mail merge with MS Word and MS Excel


When you need to send personalized letters to a large group of different people the normal procedure of creating such letters would be time consuming and repetitive. Using a mail merge can help save time consumed in doing repetitive task of preparing personalized letters having similar content or purpose. 

I learned this time saving trick from one our directors 'Anil Shenoy' during the build up to our companies annual day celebrations and thought of sharing this useful stuff with others. To create a mail merge follow the following steps: 


1) Create an excel sheet with the data to be used for sending mail merge. The data used in this example looks like this:

2) Open a word document

3) Navigate to Mailings --> Start Mail Merge --> Letters
 

4) Navigate to Mailings --> Select recipients --> Use Existing List


5) Select data source dialog will open

6) Select data source as excel sheet 

7) Point to excel sheet that was created at the beginning and select the sheet from the following dialogue

8) Add the template text for the letter as follows




9) Now place the cursor in front of the text ‘TO:’ 

10)  Click Insert Merge Field --> First_Name

11) The field will be added in front of the text ‘TO:’

12) Similarly add all the fields in the appropriate places in the word document. he document will look like this after all the fields are added


·        


13) Now click on ‘Preview Results’ and letter is ready with the data from excel sheet





14) Now you can click on ‘Finish & Merge’ to print letters to all the users in the excel sheet.