<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 4.2</li>
<li>Operating System / Platform =&gt; Windows 10</li>
<li>Compiler =&gt; Visual C++ 2019</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">This is not a duplicate of similar looking issues reported earlier because it explains how those unreleased blocks accumulate in certain cases and this situation cannot be resolved by suppressing the report as suggested here <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="556985994" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/16464" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/16464/hovercard?comment_id=579852547&amp;comment_type=issue_comment" href="https://github.com/opencv/opencv/issues/16464#issuecomment-579852547">#16464 (comment)</a></p>
<p dir="auto">Suppose there's <code class="notranslate">ProcessingModule.dll</code> made by a user and it links to <code class="notranslate">opencv_core420d.dll</code> via a .lib file - such that when anyone tries to load <code class="notranslate">ProcessingModule.dll</code> then Windows automatically loads <code class="notranslate">opencv_core420d.dll</code> too.</p>
<p dir="auto">Each time <code class="notranslate">ProcessingModule.dll</code> is loaded using <code class="notranslate">LoadLibrary()</code> Windows loads <code class="notranslate">opencv_core420d.dll</code> and this causes OpenCV to constructs some global objects some of which allocate dynamic memory. When <code class="notranslate">ProcessingModule.dll</code> is unloaded with <code class="notranslate">FreeLibrary()</code> Windows also unloads <code class="notranslate">opencv_core420d.dll</code> and dynamic memory from those global objects remains unfreed. If <code class="notranslate">LoadLibrary()</code>/<code class="notranslate">FreeLibrary()</code> are called in a loop those unreleased blocks accumulate and form a leak which gets worse over time because those global objects are created anew every time <code class="notranslate">opencv_core420d.dll</code> is loaded and those global objects are never released.</p>
<p dir="auto">So the code to reproduce the problem would be something like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="int main()
{
    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF);
   for (int c = 0; c &lt; 50; c++)
   {
        HMODULE h = LoadLibraryW(L&quot;ProcessingModule.dll&quot;);
        FreeLibrary(h);
   }
}"><pre class="notranslate"><code class="notranslate">int main()
{
    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF);
   for (int c = 0; c &lt; 50; c++)
   {
        HMODULE h = LoadLibraryW(L"ProcessingModule.dll");
        FreeLibrary(h);
   }
}
</code></pre></div>
<p dir="auto">and after this runs and the program exits there's a huge number of leaks reported in Visual Studio debugger output - about ten leaks per each iteration of the loop and all of them belong to global objects when OpenCV created for its own needs and never released. When upper limit is increased from 50 to a larger number then the number of reported unreleased blocks increases.</p>
<p dir="auto">You may say "don't write stupid programs" but the scenario above is perfectly natural when using in-proc COM servers. Here's how:</p>
<ul dir="auto">
<li>user calls <code class="notranslate">CoCreateInstance()</code> to instantiate an object which is served by <code class="notranslate">ProcessingModule.dll</code></li>
<li>Windows loads <code class="notranslate">ProcessingModule.dll</code> and also <code class="notranslate">opencv_core420d.dll</code>, those global objects are initialized</li>
<li>user releases the object he requested earlier</li>
<li>some time passes and Windows calls <code class="notranslate">DllCanUnloadNow()</code> in <code class="notranslate">ProcessingModule.dll</code> to find whether it's still serving any objects</li>
<li><code class="notranslate">ProcessingModule.dll</code> returns "no objects, you may unload me" and Windows unloads  <code class="notranslate">ProcessingModule.dll</code> and also <code class="notranslate">opencv_core420d.dll</code></li>
<li>some more time passes and user again calls <code class="notranslate">CoCreateInstance()</code> to instantiate an object which is served by <code class="notranslate">ProcessingModule.dll</code></li>
<li>the cycle continues</li>
</ul>
<p dir="auto">This is effectively the same as a "stupid for loop" above and it may occur naturally when using in-proc COM servers on Windows.</p>
<p dir="auto">This cannot be resolved by ignoring those unreleased blocks using valgrind suppressions or their equivalent.</p>
<h5 dir="auto">Steps to reproduce</h5>

<h5 dir="auto">Issue submission checklist</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I report the issue, it's not a question

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I checked the problem with documentation, FAQ, open issues,<br>
forum.opencv.org, Stack Overflow, etc and have not found solution

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I updated to latest OpenCV version and the issue is still there

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> There is reproducer code and related data files: videos, images, onnx, etc

</li>
</ul>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 4.1.0</li>
<li>Operating System / Platform =&gt;Ubuntu 18.04</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I want to test out the pipeline for stereo camera calibration and depth map estimation. I used the OpenCV sample (samples/data/left01.jpg – left14.jpg and right ...) for calibration. Is there any pair of images on which I could test depth map estimation after the stereo set has been calibrated with the <strong>given example</strong>?</p>
<h5 dir="auto">Relevant Documentation</h5>
<p dir="auto">The <a href="https://docs.opencv.org/4.1.0/dd/d53/tutorial_py_depthmap.html" rel="nofollow">camera calibration tutorial</a> uses the same sample (samples/data/left01.jpg – left14.jpg and right ...) for calibration as I did. Next, it is unclear whether the pair of images from <a href="https://docs.opencv.org/4.1.0/dd/d53/tutorial_py_depthmap.html" rel="nofollow">depth map from stereo images tutorial</a> is actually the pair of images taken with the same stereo camera that was calibrated in the previous tutorial. Also, this tutorial only shows how to compute disparity but not actually estimate the depth.</p>
<p dir="auto">It'd be great if the depth map tutorial had a stereo image pair, so that depth from this pair could be estimated using camera parameters from the calibration tutorial.</p>