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:
- The Leak Candidates view, which identifies the objects most likely to be responsible for leaked memory.
- The Object Reference Graph, Object References, and Object Details views, which provide information about objects that are holding on to memory.
- The Statistical views, which display basic profiling statistics for packages, methods, classes, and instances.
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:
- Agent Controller must be running on the machine on which you are collecting data. For information, refer to the installation guide.
- Create a profiling configuration. Read Getting started: Creating a profiling configuration for run-time problem determination.
To analyze leaks:
- 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.
- Click Profile to start your application. The Leak Candidates view opens and displays status information for the profiling run.
- If you are capturing manual heap dumps, do the following:
- 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.
- Capture the first heap dump by clicking the Capture Heap Dump button
- 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.
- In the Leak Candidates view, click the Analyze for Leaks button
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:
- 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.
- Click Profile to start your application.
- Exercise the parts of your application that you want to analyze.
- 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.
- 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.