Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks while using thread_local variables #944

Open
mwichtowski opened this issue Oct 7, 2024 · 3 comments
Open

Memory leaks while using thread_local variables #944

mwichtowski opened this issue Oct 7, 2024 · 3 comments

Comments

@mwichtowski
Copy link

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.

@daanx
Copy link
Collaborator

daanx commented Oct 8, 2024

Yikes -- that is unexpected. Thanks for the report --I'm looking into it.

@daanx
Copy link
Collaborator

daanx commented Oct 21, 2024

I cannot repro on macOS so it must be a Windows specific issue. I am currently traveling but I will get to it.

@mwichtowski
Copy link
Author

Yes, on Linux it is ok also. Problem is Windows specific.

daanx added a commit that referenced this issue Oct 21, 2024
daanx added a commit that referenced this issue Oct 23, 2024
daanx added a commit that referenced this issue Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants