You are here: Start » Technical Issues » Memory Leak Detection in Microsoft Visual Studio

Memory Leak Detection in Microsoft Visual Studio

When creating applications using Aurora Vision Library in Microsoft Visual Studio, it may be desirable to enable automated memory leak detection possible in Debug builds. The details of using this feature is described here: Finding Memory Leaks Using the CRT Library.

Some project types, notably MFC (Microsoft Foundation Classes) Windows application projects, have this mechanism enabled by default.

False Positives of Memory Leaks in AVL.dll

Using a default configuration, as described in Project Configuration can lead to false positives of memory leaks, which come from the AVL.dll library. The output of a finished program can look similar to the following:

The thread 'Win32 Thread' (0x898) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x168c) has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{5573} normal block at 0x00453DB8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{5572} normal block at 0x00453D68, 20 bytes long.
 Data: <D]NU         =E > 44 5D 4E 55 CD CD CD CD 02 00 00 00 B8 3D 45 00 
{5571} normal block at 0x00453C18, 4 bytes long.
 Data: <X NU> 58 06 4E 55 

These are not actual memory leaks, but internal resources of AVL.dll, which are not yet released when the memory leaks check is being run. Because there are many such allocated blocks reported, the actual memory leaks in your program can pass unnoticed.

Solution: Delayed Loading of AVL.dll

To avoid these false positives, AVL.dll should be configured to be delay loaded. This can be done in the Project Properties, under
Configuration Properties » Linker » Input:

Further Consequences

With this configuration, your program will not try to load AVL.dll until it uses the first function from Aurora Vision Library. This will be also connected with license checking.

The program will stop if AVL.dll is missing: if AVL.dll was not delay loaded, this would happen at start time (the program would refuse to run). This allows the program to work without AVL.dll, and use it only when it is available. The availability of AVL.dll can be checked beforehand, using LoadLibrary or LoadLibraryEx functions.

Previous: Troubleshooting Next: Data Types Visualizers