Tool Mentors > Rational Purify Tool Mentors > Profiling Memory Usage in Managed Code Using Rational Purify® and Rational PurifyPlus (Windows)

Purpose

This tool mentor describes how to use Rational Purify to profile and improve memory usage in a managed code application. This tool mentor is applicable for use with systems running the Microsoft .NET Framework on Microsoft Windows. 

PurifyPlus is a Rational product that includes Purify functionality.

To learn more about Purify, read the Getting Started manual for the PurifyPlus product family (Windows version). 

For step-by-step information about using Purify, see the Purify online Help system.

Related Rational Unified Process information:

Overview

Purify helps you identify memory problems in managed code. Using Purify, you can determine:
  • how much memory your program is using
  • how much new memory your program consumes for a specific set of actions 
  • what methods and objects in your program are consuming so much memory 
  • which objects may be preventing unneeded objects from being garbage collected 
  • where it would be advisable to force a garbage collection to improve performance

Tool Steps

To use Purify to profile a managed code application's memory usage:

    1. Run your managed code application under Purify and take a snapshot after it completes initialization
    2. Execute code that may be leaking and take another snapshot
    3. Compare the two snapshots to identify methods that may be leaking memory
    1. Examine suspect methods for unneeded objects

1. Run your managed code application under Purify and take a snapshot after it completes initialization 

The first step in Purify'ing your managed code application is to benchmark memory usage when your program has completed initialization and has reached a steady state.

Start Purify and run your program from the Purify interface. Purify intercepts messages related to memory usage from the .NET common language runtime (CLR), and uses these messages to profile the memory your program is using. After your program has finished its initialization procedures, use the Purify snapshot command to benchmark memory usage at that moment. The snapshot is your basis for investigating how your program uses memory as it runs.

   For more information, look up the following in the Purify online Help index:

  • running programs (managed code)
  • filter manager (managed code)

2. Execute code that may be leaking and take another snapshot 

The second step in Purify'ing your managed code program is to capture a record of the memory your program uses as it runs.

With your program running under Purify, execute the parts of the program that you suspect are leaking memory. Purify displays a memory allocation graph that shows variations in current memory use. When you observe an increase in allocated memory, take another snapshot.

3. Compare the two snapshots to identify methods that may be leaking memory 

The third step in Purify'ing your managed code program is to identify leaking methods.

When you have taken the second snapshot of your program's memory usage, exit your program and compare (or "diff") the two snapshots. Purify displays a call graph showing the methods that are responsible for the largest amounts of memory allocated while your program was running, between the time you took the first and second snapshots. You can focus on specific methods within the call graph to investigate them more closely.

Purify also presents memory usage data for each method in a Function List View. You can sort the list on any of the data columns and double-click on any method in the list to display more information in a Function Detail window.

If the amount of memory allocated to a method is unexpectedly large, examine your source code and revise it, if necessary, to free memory when there is no longer a need for it.

Tip: You can use the Purify Filter Manager to focus on specific class files and methods.

 For more information, look up the following topics in the Purify online Help index: 

  • comparing runs
  • call graph 
  • function list view 
  • function detail window
  • filtering data

4. Examine suspect methods for unneeded objects 

The fourth step in Purify'ing your managed code program is to identify unneeded objects.

Once you’ve identified methods that appear to have memory problems, analyze these methods at the object level. Look for objects that should be, but have not been, freed and garbage-collected, perhaps because other objects retain an unneeded reference to them. 

You can examine objects in a method's Function Detail window, which lists all objects allocated by the method. You can also use the Object List View tab of the Data Browser window to view and sort all objects that are currently allocated. 

For all details about a specific object, use the Object Detail window. This window includes a graph showing all objects in the "reference tree" to which the object belongs, as well as information about the object such as its size and the number of garbage collections it has survived. This window also displays an object dump that may contain references from the object to other objects. 

Note that you cannot examine objects from within a "diff" dataset; you have to start with a snapshot or aggregate dataset. 

For more information, look up the following in the Purify online Help index: 

  • object list view  
  • object detail window  

Copyright  © 1987 - 2001 Rational Software Corporation


Display Rational Unified Process using frames

Rational Unified Process