Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Visual studio 2012 detects memory leak in TBB

Zenju
Beginner
1,461 Views

Hi,

I'm on Windows 7 x64, Visual C++ Express 2012 Update 1, Win7.1 SDK platform, C++ 32 bit, debug build, using TBB for VC10:

When running the debug build, Visual Studio shows a number of memory leaks which after analysis were created by the TBB library. My original scenario has been rather complex, but after meticulous refactoring I was able to produce a minimal sample. I have an additional dependence to wxWidgets, an open source framework, which seems to have something to do with the leak (I suspect it's an indirect influence on the dll loading order). For some reason the combination of statically linking both wxWidgets debug dll and TBB dll causes the leak, without wxWidgets everything is fine.

On my machine I am able to consitently reproduce the behavior. So please let me know if I can help to debug this issue.

The test program is very short, so I present it here in total:

[cpp]#include <tbb/task_scheduler_init.h>
#include <tbb/parallel_for.h>

class __declspec(dllimport) wxStringBase
{
public:
wxStringBase() ;//
};

int gnaz = 0;

int main()
{
  if (gnaz != 0)
new wxStringBase;

tbb::task_scheduler_init scheduler;

tbb::parallel_for(tbb::blocked_range<int>(0, 100, 2),
[=](const tbb::blocked_range<int>& r)
{
});

return 0;
}[/cpp]

The sole purpose of the " __declspec" is to trigger static dll linkage to the wxWidgets debug library. Without this dummy class the leak is not reproducible. Also if I remove the "parallel_for" there is no leak.

Additionally I have attached the complete VS 2012 project. To get consistent results I found it is necessary to do a full project rebuild (CTRL+ALT+F7), even after changing a single file only, else, the leak is not always reproducible.

 So my question is: Is this a real leak? If not: how can the VS 2012 runtime be "pacified" to not show these messages? I cannot simply ignore the leak detector because it is an essential debugging feature. On the other hand the mere usage of TBB currently renders the leak detector useless by flooding debug messages for "leaks" that are triggered by TBB allocations.

 Best, Zenju

 Here is the debug log after program exit:

'ScalerTest.exe' (Win32): Loaded 'C:\Users\ZenJu\Desktop\ScalerTest\BUILD\ScalerTest.exe'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Program Files\C++\wxWidgets\lib\vc10_x86_debug_dll\wxbase28ud_vc_custom.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr100d.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Users\ZenJu\Desktop\ScalerTest\BUILD\tbb_debug.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp100d.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\guard32.dll'. Cannot find or open the PDB file.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
'ScalerTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\fltLib.dll'. Symbols loaded.
The thread 0x1a1c has exited with code 0 (0x0).
The thread 0x19d4 has exited with code 0 (0x0).
The thread 0x504 has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{309} normal block at 0x00A2DE98, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{308} normal block at 0x00A2DCD8, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{307} normal block at 0x00A2DB18, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{306} normal block at 0x00A2D958, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{305} normal block at 0x00A2D798, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{304} normal block at 0x00A2D5D8, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{303} normal block at 0x00A2D418, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{302} normal block at 0x00A2D248, 404 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{301} normal block at 0x00A2D1E8, 36 bytes long.
Data: <T B B W o r k > 54 00 42 00 42 00 20 00 57 00 6F 00 72 00 6B 00
{300} normal block at 0x00A2D028, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{299} normal block at 0x00A2B3E0, 28 bytes long.
Data: < > 00 00 00 00 E8 D1 A2 00 04 05 00 00 00 00 00 00
{298} normal block at 0x00A2CE68, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{297} normal block at 0x00A2CCA8, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{296} normal block at 0x00A2CAE8, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{295} normal block at 0x00A2C928, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{294} normal block at 0x00A2C768, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{293} normal block at 0x00A2B210, 404 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{292} normal block at 0x00A2B1B0, 36 bytes long.
Data: <T B B W o r k > 54 00 42 00 42 00 20 00 57 00 6F 00 72 00 6B 00
{291} normal block at 0x00A2B158, 28 bytes long.
Data: < > 00 00 00 00 B0 B1 A2 00 1C 1A 00 00 00 00 00 00
{277} normal block at 0x00A2ADD8, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{270} normal block at 0x00A2A188, 384 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{269} normal block at 0x00A2A140, 8 bytes long.
Data: < > AC 9F A2 00 00 00 00 00
{268} normal block at 0x00A2A0F8, 8 bytes long.
Data: <, > 2C 9F A2 00 00 00 00 00
{267} normal block at 0x00A2A0B0, 8 bytes long.
Data: < > AC 9E A2 00 00 00 00 00
{266} normal block at 0x00A2A068, 8 bytes long.
Data: <, > 2C 9E A2 00 00 00 00 00
{265} normal block at 0x00A29E28, 516 bytes long.
Data: < h > 04 00 00 00 68 A0 A2 00 00 00 00 00 00 00 00 00
{264} normal block at 0x00A29DE0, 8 bytes long.
Data: <L > 4C 9C A2 00 00 00 00 00
{263} normal block at 0x00A29D98, 8 bytes long.
Data: < > CC 9B A2 00 00 00 00 00
{262} normal block at 0x00A29D50, 8 bytes long.
Data: <L > 4C 9B A2 00 00 00 00 00
{261} normal block at 0x00A29D08, 8 bytes long.
Data: < > CC 9A A2 00 00 00 00 00
{260} normal block at 0x00A29AC8, 516 bytes long.
Data: < > 04 00 00 00 08 9D A2 00 00 00 00 00 00 00 00 00
{259} normal block at 0x00A29A80, 8 bytes long.
Data: < > EC 98 A2 00 00 00 00 00
{258} normal block at 0x00A29A38, 8 bytes long.
Data: <l > 6C 98 A2 00 00 00 00 00
{257} normal block at 0x00A299F0, 8 bytes long.
Data: < > EC 97 A2 00 00 00 00 00
{256} normal block at 0x00A299A8, 8 bytes long.
Data: <l > 6C 97 A2 00 00 00 00 00
{255} normal block at 0x00A29768, 516 bytes long.
Data: < > 04 00 00 00 A8 99 A2 00 00 00 00 00 00 00 00 00
{254} normal block at 0x00A28FA8, 1920 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{253} normal block at 0x00A28D68, 512 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{252} normal block at 0x00A28C80, 168 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{251} normal block at 0x00A28B40, 260 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
The program '[5228] ScalerTest.exe' has exited with code 0 (0x0).

0 Kudos
28 Replies
SergeyKostrov
Valued Contributor II
222 Views
>>...There is no reason to change the test case in any way... I did another quick test and I have not detected any memory leaks in TBB after deleting 6 more dependencies on wxWidgets library used in your project: wxmsw28u_adv.lib wxmsw28u_core.lib wxbase28u.lib wxpng.lib wxjpeg.lib wxzlib.lib and commenting out all wxWidgets related functionality in the test-case and leaving as is TBB functionality.
0 Kudos
SergeyKostrov
Valued Contributor II
222 Views
I will do another set of tests with a project from 'leaktest2.zip' some time later.
0 Kudos
Zenju
Beginner
222 Views
did another quick test and I have not detected any memory leaks in TBB after deleting
It doesn't buy anything when after changing the test case the symptoms are gone. With this "approach" any bug could be dismissed as "not reproducible". Example: When removing the TBB "parallel_for" loop, the memory leaks are also gone in CRT ML. According to your logic, this would mean that in fact TBB is causing the leaks. See the contradiction?
0 Kudos
SergeyKostrov
Valued Contributor II
222 Views
>>...According to your logic, this would mean that in fact TBB is causing the leaks. See the contradiction?... No. I want to do additional verification for wxWidget library only and it is in progress already.
0 Kudos
SergeyKostrov
Valued Contributor II
222 Views
>>... I want to do additional verification for wxWidget library only and it is in progress already... When it is done I will try to reproduce: >>... >>Data: *T B B W o r k * 54 00 42 00 42 00 20 00 57 00 6F 00 72 00 6B 00 >>{300} normal block at 0x00A2D028, 384 bytes long. >>... testing TBB library only and so far I can not reproduce it.
0 Kudos
Zenju
Beginner
222 Views
When it is done I will try to reproduce ( testing TBB library only )
Then you are still missing the main scenario of having both TBB and wxWidgets active at the same time. If the problem cannot be reproduced in isolation it essentially proves nothing.
0 Kudos
SergeyKostrov
Valued Contributor II
222 Views
[ A statement from Vladimir Polin ] >>...you need to use Intel(R) Inspector to find out whether these are real memory leaks or false positives... [ A message to Vladimir Polin ] Hi Vladimir, I hope that you will read my message... So, I've created a new VS project to verify possible memory leaks in TBB and wxWidget libraries. After intensive verifications with Visual Studio 2005 Professional, Visual Studio 2008 Professional, Visual Studio 2008 Express and Visual Studio 2010 Express Editions my statement is as follows: I have NOT detected ANY memory leaks in TBB and wxWidget libraries (!). Note: Unfortunately I don't have any editions of Visual Studio 2012 This is output from my test application compiled with VS 2010 Express: 'LeaksTestApp.exe': Loaded 'C:\WorkEnv\TestApps\LeaksTestApp\Debug\LeaksTestApp.exe', Symbols loaded. 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WorkEnv\TestApps\LeaksTestApp\Debug\tbb_debug.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\msvcp100d.dll', Symbols loaded. 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded. 'LeaksTestApp.exe': Loaded 'C:\WorkEnv\TestApps\LeaksTestApp\Debug\wxbase28ud_vc_custom.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\user32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll', Cannot find or open the PDB file 'LeaksTestApp.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', Cannot find or open the PDB file The program '[1388] LeaksTestApp.exe: Native' has exited with code 0 (0x0). I will upload the new VS project some time later since I'll be very busy for next a couple of hours. As soon as I upload please ask somebody from TBB team to verify my conclusion(s). I will archive the new project AS IS without any additional modifications ( a developer will need to make some small changes in paths to some TBB folders... ) Best regards, Sergey
0 Kudos
SergeyKostrov
Valued Contributor II
222 Views
>>...I will upload the new VS project some time later since I'll be very busy for next a couple of hours. As soon as I upload please >>ask somebody from TBB team to verify my conclusion(s)... Here it is and I hope that somebody will be able to test the application with some edition of Visual Studio 2012. Let me know if you have any questions. LeaksTestApp.zip attached.
0 Kudos
Reply