Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
tommy_developer
Total Points:
70
Status Points:
20
Green Belt
July 6, 2009 1:54 AM PDT
Memory leak from TBB when did nothing but only new/delete a task_scheduler_init.
The following sample code will cause memory leaks:

//
// create a new TBB task scheduler, the leaked bytes varies with the number of threads !!
//
tbb::task_scheduler_init *pScheduler = new tbb::task_scheduler_init(4);

//
// do nothing
//

//
// terminate the scheduler
//
pScheduler->terminate();

//
// delete the pointer
//
delete pScheduler;

If the parameter is 1, then no leaks. Will TBB deal with this situation in the future ?
Raf Schietekat
Total Points:
16,765
Status Points:
16,765
Black Belt
July 6, 2009 2:46 AM PDT
Rate
 
#1

What hardware/O.S./compiler, what TBB version, what memory allocator, did you redirect new/delete? How did you verify that it is indeed a leak, how big is it, and does it grow if you repeat the code? Why did you allocate it dynamically instead of on the stack and why do you explicitly call terminate()? Questions, questions... :-)



tommy_developer
Total Points:
70
Status Points:
20
Green Belt
July 6, 2009 3:58 AM PDT
Rate
 
#2 Reply to #1
Quoting - Raf Schietekat

What hardware/O.S./compiler, what TBB version, what memory allocator, did you redirect new/delete? How did you verify that it is indeed a leak, how big is it, and does it grow if you repeat the code? Why did you allocate it dynamically instead of on the stack and why do you explicitly call terminate()? Questions, questions... :-)


Windows/VC 9, TBB 2.1, it leaks even with one code line tbb::task_scheduler_init oScheduler(2). The leaked bytes varies with the number of threads which is the parameter passed to ctor of tbb::task_scheduler_init: 1 - 0 bytes, 2 - 384 bytes, 3 - 32 bytes,4 - 48 bytes, etc.

Raf Schietekat
Total Points:
16,765
Status Points:
16,765
Black Belt
July 6, 2009 4:14 AM PDT
Rate
 
#3 Reply to #2

OK, that should be useful to someone, but I can't make anything of it myself.



Alexey Kukanov (Intel)
Total Points:
13,376
Status Points:
13,376
Black Belt
July 6, 2009 4:31 AM PDT
Rate
 
#4 Reply to #2
Quoting - tommy_developer
Windows/VC 9, TBB 2.1, it leaks even with one code line tbb::task_scheduler_init oScheduler(2). The leaked bytes varies with the number of threads which is the parameter passed to ctor of tbb::task_scheduler_init: 1 - 0 bytes, 2 - 384 bytes, 3 - 32 bytes,4 - 48 bytes, etc.

0) Is it "vanilla" TBB 2.1, or some update?
1) How do you determine there is a leak? Some tool tells you perhaps?
2) If you put the TBB initialization into a long loop, will the memory use grow consistently? Will the tool report a proportional increase in the number of leaked objects and amount of memory ?

We do test TBB for memory leaks. Thus I am trying to understand whether your issue might be a tool false positive, a "perceived" miss due to memory object that would be reused later, or a bug we've somehow missed.

tommy_developer
Total Points:
70
Status Points:
20
Green Belt
July 6, 2009 8:16 PM PDT
Rate
 
#5 Reply to #4

0) Is it "vanilla" TBB 2.1, or some update?
1) How do you determine there is a leak? Some tool tells you perhaps?
2) If you put the TBB initialization into a long loop, will the memory use grow consistently? Will the tool report a proportional increase in the number of leaked objects and amount of memory ?

We do test TBB for memory leaks. Thus I am trying to understand whether your issue might be a tool false positive, a "perceived" miss due to memory object that would be reused later, or a bug we've somehow missed.

0) Yes, it is "vanilla" TBB 2.1.
1) Use the CRT Debugger APIs, turn on the memory leak checking bit.
2) No, it will not grow.

These are the code for enabling CRT Debugger memory leak checking:

//
// set the report mode to be file and debugger's output window
//
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG );

//
// pass the stdout stream to it
//
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );

//
// get the current flag
//
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );

//
// turn on leak checking bit
//
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;

//
// turn off _CRT_BLOCK checking bit
//
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;

//
// set flag to the new value
//
_CrtSetDbgFlag( tmpFlag );

Copy the above code before the code line "tbb::task_scheduler_init oScheduler(2);" and use "Start Debugging (F5)" or "Start Without Debugging (Ctrl + F5)" in Visual Studio to reproduce this.

Alexey Kukanov (Intel)
Total Points:
13,376
Status Points:
13,376
Black Belt
July 7, 2009 3:14 AM PDT
Rate
 
#6 Reply to #5
Quoting - tommy_developer
0) Yes, it is "vanilla" TBB 2.1.
1) Use the CRT Debugger APIs, turn on the memory leak checking bit.
2) No, it will not grow.

Thank you for the information and the code; it made it easier for me to reproduce the behavior.

I could ensure you that there is no real memory leaks. The reason why CRT debug heap reports some is that the TBB worker threads shut down asynchronously; i.e. the main application thread does not wait for them to complete. As the result, the final heap checks are performed earlier than worker threads destroy all their objects.

It is partially proved by the fact that putting TBB initializer in a loop does not increase the amount of "leaks". If you want more evidence, put a delay (e.g. Sleep for a second) in main() after all task_scheduler_init objects are destroyed (e.g. after the loop), and check if the CRT diagnostics still remain.



tommy_developer
Total Points:
70
Status Points:
20
Green Belt
July 8, 2009 2:31 AM PDT
Rate
 
#7 Reply to #6

Thank you for the information and the code; it made it easier for me to reproduce the behavior.

I could ensure you that there is no real memory leaks. The reason why CRT debug heap reports some is that the TBB worker threads shut down asynchronously; i.e. the main application thread does not wait for them to complete. As the result, the final heap checks are performed earlier than worker threads destroy all their objects.

It is partially proved by the fact that putting TBB initializer in a loop does not increase the amount of "leaks". If you want more evidence, put a delay (e.g. Sleep for a second) in main() after all task_scheduler_init objects are destroyed (e.g. after the loop), and check if the CRT diagnostics still remain.


I have tried your suggestion, now CRT diagnose no leaks. :)



Intel Software Network Forums Statistics

8439 users have contributed to 31542 threads and 100364 posts to date.
In the past 24 hours, we have 11 new thread(s) 33 new posts(s), and 45 new user(s).

In the past 3 days, the most popular thread for everyone has been /fpp interferes with breakpoints/stepping through code - again The most posts were made to IVF 11.1.051 freezes during build The post with the most views is Quoting - dannycat When I

Please welcome our newest member obi_1