Detecting memory leaks in a child process

This tutorial describes how to detect memory leaks in a child process of an application.

This tutorial covers the following:

    1. Using the launch dialog to specify the child process to monitor and the instance number of that child process.
    2. How to use the Memory Validator user interface to detect memory leaks in the child process.

Related tutorials:

Detecting memory leaks in a .Net Core application.
Detecting memory leaks in a .Net Core application child process.
Detecting memory leaks in a service.
Detecting memory leaks in a service child process.
Detecting memory leaks in an IIS ISAPI DLL.
Detecting memory leaks in ASP.Net with IIS.
Detecting memory leaks in ASP.Net with Web Development Server.

Native applications and mixed-mode applications

This tutorial applies to all native applications, .Net applications and to mixed-mode applications.

.Net Core Applications

If your application is written entirely in .Net Core, or your application is mixed-mode with the startup code written in .Net core you need to read a different tutorial, see the list of related tutorials above this.

Example Application and Child Process Application

Memory Validator ships with an example application and an example child process launched by the application. These can be found in the  following directories in the Memory Validator installation directory:

  • examples\nativeExample
  • examples\serviceWithAChildProcess\childProcess 

You need to build both of these projects. The easiest thing to do is to build the examples.sln.

Detecting memory leaks in the child process

Now that you have the example projects build, we can start collecting memory allocation data from the child process.

  1. Choose the Launch > Applications > Launch Application… option.
    Memory Validator launch applications menu
  2. The Launch dialog is displayed.
    Memory Validator native and .Net launch dialog
  3. Click Browse… next to Application to Launch and choose the executable that is going to launch the process you want to start checking for memory leaks. You can also choose a batch file or a powershell script. For this tutorial we’re going to start examples\nativeExample\Release10_0_x64\nativeExample_x64.exe.
    Memory Validator native and .Net launch a process to monitor a child process for memory leaks
  4. Now we need to specify which child processes will be launched by the parent process. Click Edit… next to Application to Monitor.
    Memory Validator native and .Net edit application to monitor
    The Applications to Monitor dialog will be displayed.
    Memory Validator native and .Net applications to monitor dialog
  5. We need to add an application definition. Click Add…. The Application to Monitor dialog will be displayed.
    Memory Validator native and .Net application to monitor dialog
  6. To add an application click Add…. The Application and DLL dialog is displayed.
    Memory Validator native and .Net Application and DLL dialog
  7. Type the path to the child process executable or use the Browse… button to open a Microsoft file dialog to select the child process executable. For this tutorial we’re going to choose the child process executable: examples\nativeExample\Release10_0_x64\childProcess_x64.exe.  
    Memory Validator native and .Net application and dll child process executable
  8. Click OK to complete adding the child process definition. Repeat steps 6 and 7 to add as many child process definitions as you need for your process.
  9. When you have added all the child process definitions click OK to close the Application To Monitor dialog.
    For this tutorial we’re only adding one child process definition, so click OK.
  10. Click OK to close the Applications To Monitor dialog.
  11. If you examine the Application to Monitor field on the launch dialog you can see it now has some entries in addition to the name of the file we’re going to launch.
    Memory Validator native and .Net application to monitor
  12. Choose the child process in the Application to Monitor field.
    Memory Validato native and .Net application to monitor child process
  13. We’re going to monitor the first childProcess_x64.exe that is launched. This is the default, indicated by the 1 in the small combo below the Application to Monitor field. If you wanted to monitor the third childProcess_x64.exe that is launched you’d set this to 3. 
  14. Now that we’ve specified the process to launch and the child process we can start the Application to Launch.
    Click Launch….
    Memory Validator starts the Application to Launch (in this tutorial that’s nativeExample_x64.exe).
  15. When nativeExample_x64.exe is running choose the Child Process menu then choose Start ChildProcess….
    Memory Validator native and .Net native example child process menu
    The child process is started. In this tutorial that’s childProcess_x64.exe.
    For childProcess_x64.exe you’ll see a cmd prompt open, there will be a pause while the application runs, then it will close.
  16. Memory Validator will instrument your applications’s child process and start collecting memory allocation data.
  17. Memory allocation data will be collected until the child process finishes executing.  For best results, we recommend closing the child process normally (do not kill it with TaskManager or TerminateProcess). 
  18. You can close the parent process whenever you want – Memory Validator is not tracking it.
  19. When the child process finishes executing Memory Validator will display the leak results.
    Memory Validator native and .Net child process memory leak results

How Do I Repeat This?

There are three method of repeating this.

  1. To repeat launching the parent process and monitoring the child process just click the relaunch button on the toolbar.

     

  2. You can open the launch dialog then double click on an entry in the list at the bottom of the dialog.
    Memory Validator native and .Net launch dialog relaunch
  3. You can open the launch dialog then select an entry in the list at the bottom of the dialog, edit any settings on the dialog, then click Launch.

I need to detect memory leaks in a grand child process or other descendant. How do I do that?

The method described above only works for child processes of a parent process.
 
If you have a process that is a descendent process deeper than a child process read this article about Loading Validator into an application.

I’m not getting any memory allocation data. What can I do?

There are a few things to check.

  1. Data Collection
    Have you got data collection turned off?
    There is a Collect data from application check box on the launch dialog.
    There are also data collection on/off buttons on the main toolbar, and Start collecting data and Stop collecting data options on the File menu.
  2. Diagnostics
    Check the diagnostics tab. If the injection and data transport is working correctly Memory Validator will have some data. Information on instrumentation failures will be on the diagnostic tab.
  3. Debug Information
    Check the debug information dialog. You can access this from the Tools > DLL Debug Information… menu. This dialog will tell you which DLLs have debug information and which do not. Any DLLs that don’t have debug information you’ll need to ensure that debug information is built for these DLLs and is findable.

Conclusion

You have learned how to launch an application and monitor a child process launched by that application, how to use Memory Validator to monitor the application’s child process, and what to look at to diagnose errors if things don’t work first time.

 

 

Fully functional, free for 30 days