I have a memory leaks with this simple code using std::thread on Visual Studio Pro 2012:
#include <thread>
void f(){}
int main(){
std::thread t(f);
t.join();
_CrtDumpMemoryLeaks();
return 0;}
Win32 Output:
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 Output:
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.
If I comment the two first lines of the main method, I have no memory leaks.
Where does it come from ?
EDIT: The leak is still here with that code:
#include <thread>
void f(){}
int main(){
{
std::thread t(f);
t.join();
}
_CrtDumpMemoryLeaks();
return 0;}
CrtDumpMemoryLeaks is notoriously unreliable. It may well be that the standard library intentionally leaks a one-time allocation when you first use std::thread. To find out if there's a real memory leak, try this:
for (int i = 0; i < LIMIT; ++i) {
std::thread t(f); t.join();
}
_CrtDumpMemoryLeaks();
And then see if the leak size increases as you increase LIMIT. If it doesn't, you're fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With