boostorg / mysql

MySQL C++ client based on Boost.Asio
https://www.boost.org/doc/libs/master/libs/mysql
Boost Software License 1.0
253 stars 32 forks source link

Documentation: Use of chrono under MSVC can cause a large memory leak #273

Closed SpareSimian closed 4 months ago

SpareSimian commented 4 months ago

FYI Using MySQL datetime support with STL and C++20 can result in a memory leak being reported under MSVC. The timezone database (tzdb) is initialized in a way that's not protected from the debugger's leak detector.

A workaround is offered here: https://github.com/microsoft/STL/issues/2504

More on the problem here: https://github.com/microsoft/STL/issues/2047

I put the workaround in my wxApp::OnExit handler and the leak no longer floods the debug output.

#ifdef _DEBUG
   // to prevent the tzdb allocations from being reported as memory leaks
   std::chrono::get_tzdb_list().~tzdb_list();
#endif
anarthal commented 4 months ago

So if I understood correctly, this is a problem in MSVC STL that won't get fixed at all, isn't it? What can we do in MySQL about it? Maybe add the info you provided to the documentation to guide other users encountering it?

anarthal commented 4 months ago

I just saw the issue title :)