我在使用Visual Studio Pro 2012上,使用std :: thread编写的这段简单代码中存在内存泄漏问题:
#include <thread>
void f(){}
int main(){
std::thread t(f);
t.join();
_CrtDumpMemoryLeaks();
return 0;}
Win32 输出:
Detected memory leaks!
Dumping objects ->
{293} normal block at 0x00A89520, 44 bytes long.
Data: < > 01 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00
Object dump complete.
x64输出:
Detected memory leaks!
Dumping objects ->
{293} normal block at 0x00000000003FCB00, 72 bytes long.
Data: < > 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
如果我注释掉主方法的前两行,就不会有内存泄漏。
这是怎么回事?
编辑:即使使用这段代码,泄漏仍然存在。
#include <thread>
void f(){}
int main(){
{
std::thread t(f);
t.join();
}
_CrtDumpMemoryLeaks();
return 0;}