Launch the sample application
The sample application will be launched from the Profiling and Logging perspective.
Switch to the Profiling and Logging perspective by selecting Window > Open perspective > Other > Profiling and Logging.
Click on the launch profiling button Launch profiling configuration icon and select Profile...
In the Profile configuration dialog, double-click on Java Application. A new configuration is created and the details are shown in the right pane.
Specify the project name as CarModel.
Click on Search for the main class. The wizard should automatically detect the CarModel class.
Select the CarModel class and click OK.
Specifiying profiling filters
Profiling filters allow users to limit the amount of data that is collecting in a profiling session. Follow these steps to set up filters for the sample application:
In your profiing configuration, under the Profiling tab, select the Overview tab.
Click Add to add your own profiling set. The Add Profiling Set wizard opens.
On the Profiling Set page, specify a name and a description for your profiling set (IBM Test 257 Profiling Set). Click Next.
On the Profiling Type page, expand the Memory Analysis check box.
Check the Basic Memory Analysis. The details of this profiling set are shown in the right pane.
Select the Show instance level information option.
On the Filter Set page, specify the filter set that you want applied by selecting from the Select a filter set list. You can use the Default set.
Under Contents of selected filter set, click Add.
Specify by* as the Class and main as the Method Name.
Select INCLUDE from the Rule list.
Click OK. The filter criterion is added to the contents list.
Click Apply to save the changes.
Click Profile to start profiling your application. The Profiling Monitor will show the CarModel application started.
NOTE: You should have RAServer running:
Memory Statistics view
From the Profiling Monitor view, using the pop-up menu of the profiling agent, select Open with > Memory Statistics.
In the Memory Statistics view, expand the by.iba.rad257 package.
Select CarModel. Notice the information provided for the class:
Total instances: The total number of instances of the CarModel class.
Live instances: The number of instances that are alive (i.e. instances that were not collected by the garbage collector).
Collected: The number of instances that have been garbage collected.
Total Size (bytes): The size of an instances associated with a specific type.
Active Size (bytes): The size of an instances associated with a specific type.
From the toolbar, select Class Level Information icon to open the class level information. Notice that all the non-filtered invoked methods of the CarModel class appear under its name. The filtered main method which has already been invoked at this point, does not appear under the class.
Select Instance Level Information icon from the toolbar to open the instance level information. The number of instances associated with a specific object type are listed beneath the object.
Java memory leak detection using RAD 6
IBM Rational Application Developer can identify potential leaks by analyzing heap dumps. A heap dump is the state of heap memory at a given point in time, and RAD has the ability to profile an application and collect heap dumps. Alternatively, you can import heap dumps with tools taken on various platforms. RAD can then analyze these heap dumps and find Java leaks.
Before collecting heap dumps, make sure that the IBM Agent Controller is running. It is packaged and gets installed with RAD.
Heap dumps can be collected by profiling a program, using these steps in the Profiling dialog.
To start the Profiling dialog, from the Run menu, click Profile...
You want to collect heap dumps for LeakExample program. You will have to create a Configuration for it under the Java Application.
Then go to the Profiling tab and select the Memory Leak Analysis - Manual heap dumps profiling set.
Once you click the Profile button, RAD will switch to the Profiling and Logging Perspective. RAD will start your application and begin profiling. It will be shown in the Profiling Monitor View in the perspective.
You can collect a heap dump by clicking the Capture Heap Dump button. Collect at least two heap dumps. Typically, you should take these heap dumps just before and after the sequence of operations suspected to cause leak. Or it could just be at the beginning and end of the program.
When you have collected the dumps, terminate the program.
Once you have collected the heap dumps, you can analyze them for leaks by clicking the Analyze for Leaks button.
It will bring up the Select Leak Analysis Options dialog, in which you should select two heap dumps, set the threshold value to 1, and click the OK button.
RAD will perform leak analysis and bring up the Leak Candidate view. RAD found that there are two potential leak candidates: first is a Vector in LeakExample accumulating String, and the second is a HashMap.
RAD allows you to browse the Object Reference Graph in a heap dump. If you right click a leak candidate in the Leak Candidate view and select Show Object References, it will bring up the Object Reference Graph with a highlighted path characterizing the leak.
For example, if you click the first leak candidate (that is, LeakExample class having a Vector that is leaking String objects), RAD will bring up the Object Reference Graph with the path from LeakExample to Vector to String highlighted. This is very helpful for non-trivial programs having complex object containment and ownership. By looking at this path, you can start from the class that is the root of the leak (LeakExample) and trace down to the object that is leaking.