Detecting memory leaks in a .Net Core application child process

This tutorial demonstrates launching a .Net Core application, closing the application and inspecting the memory leak results. 

Building the example applications

For this tutorial we’re going to work with dotNetCoreLauncher and consoleApp which are located in <Memory Validator install directory>\examples\dotNetCore\.

You will need to build these with Visual Studio 2019 (.Net Core 5) or Visual Studio 2022 (.Net Core 6). A solution file is provided for each version. If you’ve installed in the default program files location you’ll need to run Visual Studio in administrator mode to do the build.

We’re going to show you how to detect memory leaks for a child process launched from a .Net Core application. The process is the same for both Framework-dependent and Self-contained .Net Core applications. But the process is slightly different depending on whether the child process is Framework-dependent, Self-contained, .Net or native.

Publishing the application

Publishing the .Net Core application allows you to create an application that is framework dependent, or which is self contained.

The following command will create a framework dependent version and a self contained x64 version using Visual Studio 2019 and Visual Studio 2022.

Open a command prompt with administrator privileges.

cd c:\Program Files (x86)\Software Verify\Memory Validator x64\examples\dotNetCore

publish.bat

You can also use publish_vs2019.bat and publish_vs2022.bat for use with specific versions of Visual Studio.

Framework dependent .Net Core

  • Launch the sample application. Click on the launch icon on the toolbar.
    Coverage Validator launch toolbar
  • The Launch Application or Service dialog is displayed.
    Coverage Validator launch .Net Core application ro service dialog
  • Click Launch .Net Core Applications. The Launch .Net Core application dialog is displayed. By default it is configured for Framework Dependent .Net Core applications. You can change that from the .Net Core Application Type combo. For this tutorial we’ll leave it set to Framework Dependent.
    Coverage Validator .Net Core launch dialog, framework dependent
  • We’re going to start dotNetCoreLauncher that we just built with publish.bat. This is in <Memory Validator install dir>\examples\dotNetCore\dotNetCoreLauncher\dotNetCoreLauncher\bin\debug\net5.0\win-x64\. You may need to replace net5.0 with net6.0 on your machine.

    Select the dotNetCoreLauncher_vs2019.dll using the Browse… button next to the Application to launch (*.dll) field.

    When you do this the Application to launch (*.exe) and Application to Monitor fields are populated with the .Net Core runtime, and the Application to launch (*.dll) is populated with the choice of dll. 
    Memory Validator .Net Core Launch dialog application to launch

  • Now we need to specify the child process that we want to monitor. Click Edit… next to the Application to monitor (*.exe) field. 
    Memory Validator Edit Application to Monitor
  • The Applications to Monitor dialog is displayed.
    Memory Validator Applications to Monitor dialog
  • We need to add an application that we want to monitor. Click Add…
  • The Application to Monitor dialog is displayed.
    Memory Validator .Net Core Application to Monitor dialog
  • This dialog allows us to specify the .Net Core application that is being launched and which child applications you want to monitor. The application being launched has already been configured based on your choices on the .Net Core launch dialog. You can specify as many child applications as you want. For this example we’re going to specify two child applications.
  • To add the first application click Add…. The Application and DLL dialog is displayed.
    Memory Validator .Net Core Application and DLL dialog
  • We’re going to launch a .Net application, so leave the application type as it is. Click Browse… and choose <install dir>\examples\dotnetExample\bin\Release10_0\dotnetExample10_0.exe. Then click OK to accept this choice.
    Memory Validator .Net Core Application and DLL Add Application .Net Example
  • To add the second application click Add…. The Application and DLL dialog is displayed.
  • We’re going to launch a self contained .Net application, so change the Application Type to .Net Core (Self Contained). Click Browse… and choose <install dir>\examples\dotNetCore\consoleApp\consoleApp\bin\Debug\net5.0\win-x64\consoleApp_vs2019.exe. Then click OK to accept this choice.
    Memory Validator .Net Core Application and DLL Add Application Self Contained ConsoleApp
  • The Application to Monitor dialog should now show four entries (for two applications) in the list. Click OK.
    Memory Validator .Net Core Applications to Monitor dialog with 4 entries
  • The Applications to Monitor dialog will now show an additional entry in the list. Click OK.
    Memory Validator .Net Core Applications To Monitor dialog with 2 entries
  • Now that we have configured which child applications we want to monitor we choose an application. The Application to Monitor combo will display <<Any application that is launched>>, the name of the application we are launching, and the names of all the child applications that have been configured. You may need to widen the dialog to see the full path in the combo. Select <install dir>examples\dotNetCore\consoleApp\consoleApp\bin\Debug\net5.0\win-x64\consoleApp_vs2019.exe consoleApp_vs2019.dll.
  • Click the Launch button to launch the application.
  • The .Net Core dotNet.exe runtime is started to run the dotNetCoreLauncher_vs2019.dll application.
  • Memory Validator displays no memory information because although an application has been started that is not the application we are monitoring.
    Coverage Validator .Net Core launcher
  • Choose 2 to launch dotNetExample. dotNetExample is launched but memory allocation information is not collected because you didn’t choose dotNetExample in the Application to Monitor combo. Close dotNetExample.
  • Choose 5 to launch the win-x64 configuration of self contained .Net Core consoleApp_vs2019.exe. consoleApp_vs2019.exe is launched and Memory Validator starts collecting memory allocation information.
  • Choose 0 to exit consoleApp_vs2019.exe.
  • The application closes. Memory Validator processes any remaining data and displays the final results.
    Memory Validator .Net Core memory leak results on Summary view
  • The memory leak results are displayed on the Memory tab. These have been discussed in previous tutorials, we will not repeat that discussion here.

Self Contained .Net Core

The process for self contained .Net Core is very similar to the process described above for Framework Dependent .Net Core.

The difference is just how you specify the application to launch.

How you specify the child processes to monitor is identical to the process for Framework Dependent .Net Core.

  • Launch the sample application. Click on the launch icon on the toolbar.
    Coverage Validator launch toolbar
  • The Launch Application or Service dialog is displayed.
    Coverage Validator launch .Net Core application ro service dialog
  • Click Launch .Net Core Applications. The Launch .Net Core application dialog is displayed. Change the .Net Core application type to Self Contained using the .Net Core Application Type combo. 
    Coverage Validator .Net Core launch dialog self contained
  • We’re going to start dotNetCoreLauncher that we just built with publish.bat. This is in <Memory Validator install dir>\examples\dotNetCore\dotNetCoreLauncher\dotNetCoreLauncher\bin\debug\net5.0\win-x64\. You may need to replace net5.0 with net6.0 on your machine.

    Select the dotNetCoreLauncher_vs2019.exe using the Browse… button next to the Application to launch (*.exe) field.

    When you do this the Application to launch (*.dll) and Application to Monitor fields are populated with the executable, and the Application to launch (*.dll) is populated with a .Net Core dll that has the same name as the executable. 
    Memory Validator .Net Core Self contained application Launch dialog

  • From this point on, please follow the tutorial process described above for Framework Dependent .Net Core, starting with Now we need to specify the child process that we want to monitor.

Fully functional, free for 30 days