mimalloc
mimalloc copied to clipboard
Memory leaks while using thread_local variables
Here is sample program (mimalloc 1.8.7 and 2.1.7):
#include <chrono>
#include <cstdio>
#include <thread>
// Build with: cl /MD mimalloc_tl_test.cpp mimalloc-override.lib /link /INCLUDE:mi_version
class MTest
{
char *data;
public:
MTest() { data = (char*)malloc(1024); }
~MTest() { free(data); };
};
thread_local MTest tlVariable;
void threadFun( int i )
{
printf( "Thread %d\n", i );
std::this_thread::sleep_for( std::chrono::milliseconds(100) );
}
int main( int argc, char* argv[] )
{
for( int i=1; ; ++i )
{
std::thread t( threadFun, i );
t.join();
}
return 0;
}
Committed memory increases indefinitely. Without 'mimalloc', everything is ok.