Enabling heap memory profiling

Before you profile an application, you should fix its memory errors. You can use the Memory Analysis tool to find these errors. After you've fixed them, you can profile your application's heap memory usage to achieve two goals: performance improvements (because using heap memory is expensive), and heap optimization (for producing a smaller memory footprint).
To enable heap memory profiling:
  1. Build the binary with debug information (see Building an executable for debugging).
    Debug information is required in order to match the analysis results with source code.
  2. Create a launch configuration to run your application (see Creating a launch configuration).
  3. In the launch configuration dialog, select the Tools tab.
  4. Click Add/Delete Tool at the bottom.
  5. In the Tools selection dialog, check the Memory Analysis box and click OK.
  6. Expand Memory Errors and configure memory leak checking.
    Option Description
    If your application runs for a finite amount of time, then exits Uncheck the boxes for all specific error checks except for Perform leak check when process exits.
    If your application runs continuously (i.e., never exits) Uncheck the boxes for all specific error checks, and in Perform leak check every (ms), specify an interval, in milliseconds, for periodically checking for memory leaks.
    Note: It's sometimes sufficient to check for leaks only once when you run the application because the leaks might be duplicated. Also, the leak detection process takes significant time.
  7. Expand Memory Tracing and check the Record memory allocation/deallocation events box.
  8. Expand Memory Snapshots, check the Memory Snapshots box, and in Perform snapshot every (ms), enter an interval for recording heap usage details.
  9. Enable the Switch to this tool's perspective on launch option at the bottom of the page.
  10. Click Run or Debug to launch the application.
The IDE switches to the Memory Analysis perspective and displays a new session in the Session View.
Let the application run for a suitable amount of time (e.g., you may perform a testing scenario), then either stop it from the IDE or let it terminate itself. Now, the Memory Analysis session will contain the memory snapshot results. For details on reading these results, see Viewing Memory Analysis data.