Finding Memory Leaks

Introduction

The OSPSuite.SimModel is a the component of the OSPSuite, written mainly in C++, that reads the model description in its XML format, creates a differential equations system from it and solves it. In this part of the documentation we will describe how to use the Visual Leak Detector to detect memory leaks in the C++ code.

Using the Visual Leak Detector

Looking for memory leaks in SimModel when used in PK-Sim (MoBi, etc. - same procedure)

  1. Install Visual Leak Detector for Visual C++ (VLD) from https://github.com/KindDragon/vld/releases EDIT 2022: VLD development continues now here: https://github.com/Azure/vld (latest release: https://github.com/Azure/vld/releases)

  2. Open SimModel solution in Visual Studio and uncomment the line #include <vld.h> in src/OSPSuite.SimModelNative/src/Simulation.cpp

  3. If VLD was installed NOT into the default path: open project settings of OSPSuite.SimModelNative and adjust the paths in the Debug-configuration grafik

  4. Build the Debug version of OSPSuite.SimModelNative

  5. Copy OSPSuite.SimModelNative.dll and OSPSuite.SimModelNative.pdb from <SimModel_SolutionDir>\Build\Debug\x64 into the PK-Sim folder

  6. Copy the Debug version of OSPSuite.FuncParserNative.dll and OSPSuite.FuncParserNative.pdb from the corresponding Nuget package into the PK-Sim folder

  7. Copy the Debug version of OSPSuite.SimModelSolver_CVODES.dll and OSPSuite.SimModelSolver_CVODES.pdb from the corresponding Nuget package into the PK-Sim folder

  8. Open "C:\Program Files (x86)\Visual Leak Detector\vld.ini" in a text editor and set

  • AggregateDuplicates = yes

  • ForceIncludeModules = <list of additional C++ libs to include> E.g. to profile FuncParser as well: ForceIncludeModules = OSPSuite.FuncParserNative.dll

  • ReportFile = <path to report file> Leak report will be created here E.g. ReportFile = C:\Temp\SimModelLeaks.txt

  • ReportTo = file or ReportTo = both

  • StackWalkMethod = fast

  1. Start PK-Sim and perform actions you would like to profile (run individual/population simulations, perform sensitivity analysis, parameter identifications, ...)

  2. Close PK-Sim. Leak report is now available in the <path to report file> defined in vld.ini

Example vld.ini
Example VLD report (no leaks)
Example VLD report (leaks detected)

Remarks

  • For additional included C++ modules: in order to get readable stack trace, Whole Program Optimization (/GL) Compiler option must be set

Last updated