<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 3.4.2</li>
<li>Operating System / Platform =&gt; Android P</li>
<li>Compiler =&gt; clang</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">libc.debug.malloc detec the memory leak when used getCoreTlsData() although implement singleton lazy initialization  is already included.</p>
<p dir="auto">256,1,"#00 pc 0xc934 /system/lib64/libc_malloc_debug.so (InternalMalloc(unsigned long)+0x164)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5857810" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/1" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/1/hovercard" href="https://github.com/opencv/opencv/pull/1">#1</a> pc 0xc768 /system/lib64/libc_malloc_debug.so (debug_malloc+0x60)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5867398" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/2" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/2/hovercard" href="https://github.com/opencv/opencv/pull/2">#2</a> pc 0x715e5c /vendor/lib64/libwa_depth.so (operator new(unsigned long)+0x20)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5907046" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/3" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/3/hovercard" href="https://github.com/opencv/opencv/pull/3">#3</a> pc 0x5297b0 /vendor/lib64/libwa_depth.so (cv::TlsStorage::setData(unsigned long, void*)+0x94)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5915756" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/4" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/4/hovercard" href="https://github.com/opencv/opencv/pull/4">#4</a> pc 0x5295bc /vendor/lib64/libwa_depth.so (cv::TLSDataContainer::getData() const+0x64)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5931862" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/5" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/5/hovercard" href="https://github.com/opencv/opencv/pull/5">#5</a> pc 0x513110 /vendor/lib64/libwa_depth.so (cv::theRNG()+0xc)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="5936931" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/6" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/6/hovercard" href="https://github.com/opencv/opencv/pull/6">#6</a> pc 0x4f0088 /vendor/lib64/libwa_depth.so (cv::parallel_for_(cv::Range const&amp;, cv::ParallelLoopBody const&amp;, double)+0x15c)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="6069994" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/7" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/7/hovercard" href="https://github.com/opencv/opencv/pull/7">#7</a> pc 0x38f7e0 /vendor/lib64/libwa_depth.so (cv::threshold(cv::_InputArray const&amp;, cv::_OutputArray const&amp;, double, double, int)+0xab0)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="6103928" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/8" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/8/hovercard" href="https://github.com/opencv/opencv/pull/8">#8</a> pc 0xba430 /vendor/lib64/libwa_depth.so (PortraitEdgeRefine::getConfidenceMapFBS()+0x154)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="6120770" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/9" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/9/hovercard" href="https://github.com/opencv/opencv/pull/9">#9</a> pc 0xb7ee8 /vendor/lib64/libwa_depth.so (PortraitEdgeRefine::runFilter(cv::Mat const&amp;, cv::Mat const&amp;, std::_<em>ndk1::vector&lt;cv::Rect</em>, std::_<em>ndk1::allocator&lt;cv::Rect</em>&gt;&gt; const&amp;)+0xc5c)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="6291469" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/10" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/10/hovercard" href="https://github.com/opencv/opencv/pull/10">#10</a> pc 0xbed90 /vendor/lib64/libwa_depth.so (<em>ZNSt6__ndk114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEM18PortraitEdgeRefineFvRKN2cv3MatESB_RKNS_6vectorINS8_5Rect_IiEENS_9allocatorISE_EEEEEPS7_S9_S9_SH_EEEEEPvSO</em>+0x48)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="6311084" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/11" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/11/hovercard" href="https://github.com/opencv/opencv/pull/11">#11</a> pc 0x83114 /system/lib64/libc.so (__pthread_start(void*)+0x24)<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="6314176" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/12" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/12/hovercard" href="https://github.com/opencv/opencv/pull/12">#12</a> pc 0x233bc /system/lib64/libc.so (__start_thread+0x44)</p>
<p dir="auto">When it try to use parallel_for_, it should use<br>
cv::RNG&amp;  cv::theRNG(){<br>
return getCoreTlsData().get()-&gt;rng;<br>
}<br>
if getData() return null , it will new ThreadData() in setData()  but it will not be released. nobody call releaseThread(). so the new ThreadData() maybe  leaked.</p>
<p dir="auto">Can we release it with pthread_key_create 2nd parameter after thread finish?<br>
int pthread_key_create(pthread_key_t *key, void (<em>destructor)(void</em>));</p>
<p dir="auto">modules/core/src/system.cpp<br>
TlsAbstraction::TlsAbstraction()<br>
{<br>
CV_Assert(pthread_key_create(&amp;tlsKey, release_threadData) == 0);<br>
}<br>
void release_threadData(void* thread_data)<br>
{<br>
getTlsStorage().releaseThread();<br>
}</p>
<ul dir="auto">
<li>OpenCV =&gt; 3.3.0</li>
<li>Operating System / Platform =&gt; Arch Linux (4.12.13-1-ARCH SMP PREEMPT x86_64 GNU/Linux)</li>
<li>Compiler =&gt; gcc 7.2.0 and clang 5.0.0</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">It seems that a significant portion of memory is leaked in every thread.<br>
The following code snippet consumes cca 100MB/s.</p>
<h5 dir="auto">Steps to reproduce</h5>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#include &lt;opencv2/opencv.hpp&gt;
#include &lt;future&gt;
int main()
{
    while(true) {
        std::async(std::launch::async, []() { cv::Mat::zeros(1, 1, CV_32FC3); }).wait();
    }
}"><pre class="notranslate">#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>opencv2/opencv.hpp<span class="pl-pds">&gt;</span></span>
#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>future<span class="pl-pds">&gt;</span></span>
<span class="pl-k">int</span> <span class="pl-en">main</span>()
{
    <span class="pl-k">while</span>(<span class="pl-c1">true</span>) {
        <span class="pl-c1">std::async</span>(std::launch::async, []() { <span class="pl-c1">cv::Mat::zeros</span>(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, CV_32FC3); }).<span class="pl-c1">wait</span>();
    }
}</pre></div>