<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.2.0</li>
<li>Operating System / Platform =&gt; Windows 10 64 Bit</li>
<li>Compiler =&gt; MSVC++ 14.24</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">The static variables named "__initialization_mutex" are never freed, causing (false) memory leak detections.<br>
For example one such variable is in modules/core/src/system.cpp .</p>
<p dir="auto">IPP also produces a lot of false positives since it leaves a lot of TLS objects on the heap without cleaning them up upon unloading the DLL (exiting the application). But IPP can be disabled.</p>
<p dir="auto">I have not yet checked if this issue is also present on linux or not.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">I used <a href="https://docs.microsoft.com/en-us/visualstudio/debugger/finding-memory-leaks-using-the-crt-library?view=vs-2019" rel="nofollow">link</a> to check for memory leaks, linked OpenCV (compiled from source) as a DLL to my application.</p>
<p dir="auto">There is a solution in <a href="https://answers.opencv.org/question/121272/false-memory-leaks-in-mfc/" rel="nofollow">link</a> that gets rid of this issue in certain cases.</p>
<p dir="auto">From question asked on stackoverflow: <a href="http://stackoverflow.com/questions/32845535/opencv-3-0-visual-studio-memory-leak-detector-false-positive" rel="nofollow">http://stackoverflow.com/questions/32845535/opencv-3-0-visual-studio-memory-leak-detector-false-positive</a></p>
<p dir="auto">If I enabled memory leaks detector in Visual Studio (to detect leaks in my application) I have always some additional memory leaks from OpenCV and it's very difficult to find out the real memory leak from my application.</p>
<p dir="auto">The leak comes from function: opencv/modules/calib3d/src/stereobm.cpp file.<br>
In function: StereoBMImpl-&gt;compute() we have statement:<br>
if(ocl::useOpenCL() &amp;&amp; disparr.isUMat() &amp;&amp; params.textureThreshold == 0)</p>
<p dir="auto">The function: ocl::useOpenCL invokes getCoreTlsData() and this function executes operator new but never deletes this object:<br>
static TLSData *value = new TLSData();</p>
<p dir="auto">I disabled OpenCL but this code is still executed and memory leak is also reported.</p>
<p dir="auto">I suppose this error isn't dangerous because it's assignment to static object, but it makes very difficult to find out leaks in applications which links to OpenCV.</p>