Exercise 1.2: Capturing heap dumps

Before you begin, you must complete Exercise 1.1: Importing the required resource.

Scenario

Your organization has a three-tiered queuing system that is part of a web proxy application. Each tier of the queuing system has its own queue. The testing team has determined that the application has a memory leak, and suspects that it is in the queuing system. As the developer of one of the queues, you have been given the job of determining which tier is responsible for the memory leak.

Overview

To perform memory leak analysis, you need to capture two Java heap dumps.

The heap is a block of memory that the Java virtual machine (JVM), when running, uses to store Java objects. Java heap memory is managed by a garbage collector, which automatically deallocates memory for Java objects to which there are no remaining references.

A heap dump is an image of the contents of the heap at a specific moment.

You need two heap dumps so that you can see how memory usage changes between two points in your application's run. A built-in algorithm compares the heaps and identifies objects that stay in memory when they should not. The algorithm analyzes the following indicators to identify potential leaks: Objects that are in memory for the entire time interval between the two heap dumps, an increase in the number of objects of a given class in the second heap, and the number of references to an object.

Preparing to capture the heap dumps

To capture heap dumps, you must switch to the Profiling and Logging perspective:

  1. From the Software Development Platform menu bar, select Window > Open Perspective > Other... The Select Perspective dialog box opens.
  2. In the lower-left part of the dialog box, click Show all. A check appears in the check box.
  3. From the list of perspectives, select Profiling and Logging and click OK.
  4. If the Confirm Enablement dialog box opens, click Always enable capabilities and don't ask me again, then click OK.
  5. The Software Development Platform switches to the Profiling and Logging perspective.

Capturing the heap dumps

For this tutorial, you are going to capture the heap dumps manually. (Alternatively, you could set time intervals for capturing heap dumps automatically, or import existing heap dumps.)

To capture the heap dumps:

  1. Run the application:
    1. From the menu bar, select Run > Profile... The Profile dialog box opens.
    2. In the Configurations list, double-click Java Application. A New_configuration entry appears in the list.
    3. In the Name field, type ThreeTierQueue_MemLkAnalysis.
    4. In the Main tab, next to the Project field, click Browse. The Project Selection dialog box opens.
    5. Select ThreeTierQueue, and then click OK.
    6. Next to the "Main class" field, click Search.
    7. In the Choose Main Type dialog box, select TestThreeTierQueue, and then click OK.
    8. In the Profile dialog box, click the Profililng tab.
    9. In the Overview sub-tab, check the check box for the "Memory Leak Analysis - Manual heap dumps" profiling set. (A profiling set defines the type of profiling data that is to be collected for the run.)
    10. Click Profile. The application runs, and the display changes as follows:
      • A Profiling resource for the process appears in the Profiling Monitor.
      • The Leak Candidates view opens, and displays a Current Status message with instructions about what to do next.
        Note: If you get a Security Message that Agent Controller is not available, read If you were unable to collect data.
  2. Capture the heap dumps:
    1. From the menu bar, select Window > Show View > Console to open the Console view, so that you can follow the application as it processes.
    2. Let the application warm up for about half a minute, to make sure that all the classes that you want to profile are loaded and initialized.
    3. Follow the instructions in the Leak Candidates view: Click the Capture Heap Dump toolbar button to capture your baseline heap dump, the starting point for the heap comparison. Additional profiling resources now appear in the Profiling Monitor view, one for Automatic Leak Detection, and one for the heap dump that you have just captured.
    4. Let the application run for another minute, and, again following the instructions in the Leak Candidates view, capture a second heap dump in the same way. A profiling resource for the second heap dump appears in the Profiling Monitor.
    5. Click the Terminate button in the Console view to terminate the process.

If you were unable to collect data

Before you can collect any kind of profiling data, Agent Controller must be running. If you get a message that Agent Controller is not available, make sure that Agent Controller has been installed, start it manually, and try again. For instructions, refer to the installation guide. You can access the installation guide by using the launchpad, or you can find it on the product CD under disk1/install.html.

After you have collected data, you are ready to begin Exercise 1.3: Analyzing leak candidates.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.