Answer the question
In order to leave comments, you need to log in
Memory leak when using std::thread in visual studio 2012?
The following code gives two memory leaks, one is explicit (for the test), the other I don’t understand from where, apparently in the implementation of the C ++ library from Microsoft.
Tell me how to deal with this. Thank you in advance.
#include <thread>
#include <iostream>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
void func(int param)
{
std::cout << param << "\n";
}
int main()
{
int tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
// always perform a leak check just before app exits.
tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(tmpDbgFlag);
int* ptr_leak = new int(0xF0F0F0F0);
{
std::thread t(&func, 1); // second memory leak! WHY? Can I do something?
if (t.joinable())
{
t.join();
}
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question