This is most likely a false positive, not a mistake. There are at least a few reasons:
- TBB uses its own
libtbbmalloc memory libtbbmalloc ; it caches memory until the process is complete and may appear as a leak. - TBB streams are executed and terminated asynchronously. Probably after the completion of
main() worker threads are still working. This gives the same impression of valgrind
To reasonably blame TBB for leakage, eliminate the above factors, for example:
- delete the libtbbmalloc.so.2 or tbbmalloc.dll file, so running the application using env.variable
TBB_VERSION=1 will output TBB: ALLOCATOR malloc , but not TBB: ALLOCATOR scalable_malloc - make sure all TBB streams are complete.
for instance
int main() { assert(tbb::tbb_allocator<int>::allocator_type() != tbb::tbb_allocator<int>::scalable); { // TBB scope tbb::task_scheduler_init scope; tbb::parallel_invoke([]{},[]{}); } // TBB threads start termination here sleep(10); // wait for threads to terminate return 0; }
Anton source share