Getting started: Memory leak analysis

Memory leaks, which in Java often result when objects hold on to references inappropriately, can degrade performance and eventually cause a program to crash. The Profiling and Logging perspective includes views for analyzing your application's memory usage and detecting these leaks.

The following views are available for memory leak analysis:

After identifying a leak, you can use Probekit to design custom probes to investigate specific objects that might be leaking.

To identify leak candidates quickly, perform memory leak analysis by profiling with a Memory Leak Analysis profiling set. You can also examine memory usage by profiling with the Memory Analysis profiling set; you can browse this data with the Object Reference Graph, the Object References, and the Object Details views, but you cannot use the data to generate a list of leak candidates.

 

Parent topic

Getting started with run-time problem determination

Performing memory leak analysis

Memory leak analysis uses advanced algorithms to identify potential memory leaks based on a comparison of two heap dumps. You can define a profiling configuration either to allow you to capture heap dumps manually, or to capture heap dumps automatically at times that you specified in the profiling set.

Prerequisites:

To analyze leaks:

  1. In the Profiling tab of the Profile dialog box, select either the Memory Leak Analysis - Manual heap dumps or the Memory Leak Analysis - Timed heap dumps profiling set.

  2. Click Profile to start your application. The Leak Candidates view opens and displays status information for the profiling run.

  3. If you are capturing manual heap dumps, do the following:

    1. Warm up your application: Use the application until everything that should be in memory is in memory. Execute the transactions that you want to investigate several times.

    2. Capture the first heap dump by clicking the Capture Heap Dump button

      Capture heap dump button in the Leak Candidates view. The heap dump is added in the Profiling Monitor as a profiling resource.

    3. Perform the transactions that you want to investigate several more times.

    4. Capture a second heap dump. You can now terminate your application.

  4. If you are capturing timed heap dumps, allow your application to run until the Leak Candidates view indicates that both heap dumps have been captured and that you can start analysis. By default, the first heap dump is captured after 10 minutes (600 seconds), and the second is captured after an additional 10 minutes. You can now terminate your application.

  5. In the Leak Candidates view, click the Analyze for Leaks button

    Analyze for leaks button.

  6. In the Select Leak Analysis Options dialog box, click OK. When analysis is complete, the Leak Candidates view lists objects in the heap that were still holding references to objects at the time of the second heap dump, with the objects most likely to be leaking memory listed first.

  7. Double-click the most likely leak candidate to display it in the Object Reference Graph view. The graph highlights the path between the root of the leak (the object that is holding the references) and the potentially leaked object; this allows you to navigate through the graph. You can display statistical information about any object or path segment by pausing your cursor over it. In this way, you can investigate how much memory is being held, and consider whether it is possible to remove any of the references.

  8. Double-click an object in the Object Reference Graph view to display object information in the Object Details view. This view displays all information about the current object in tabular format, including additional data about the object’s referers (objects that refer to the current object) and referees (objects to which the current object refers).

You can now modify your code to clean up the references that are no longer useful, so that the garbage collector can collect unneeded objects. Profile your application again to verify that you have fixed the leak, and to detect additional leaks.

For more information, read Analyzing memory leaks.

Investigating memory usage with memory analysis

The Memory Analysis profiling set, with the Memory/Leak Analysis profiling type, allows you to collect object references and view heap dumps. Note that you can view this data in the Object Reference Graph, Object References, and Object Details views, but you cannot use it to generate a list of leak candidates.

To investigate memory usage:

  1. In the Profiling tab of the Profile dialog box, select the Memory Analysis profiling set. Note that this profiling set does not identify leak candidates automatically.

  2. Click Profile to start your application.

  3. Exercise the parts of your application that you want to analyze.

  4. In the Profiling Monitor, right-click the agent profiling resource and select Collect Object References from the pop-up menu. You can now terminate your program. A profiling resource with the data collected for the run appears in the Profiling Monitor.

  5. To display object references, right-click the profiling resource and from the pop-up menu select Open With..., followed by the name of the view you want to display.