Boost C++ Libraries: Ticket #11951: Memory leak in boost::when_all https://svn.boost.org/trac10/ticket/11951 <p> After trying to identify the source of huge memory leak in our product we found that problem sits inside boost::when_all. </p> <p> I have written a minimal program to demonstrate it. It simply constructs many promises, extracts the future from them and assign continuation to boost::when_all future. Then it waits for completition and loop. </p> <p> Run <code>htop</code> and see how memory infinitly consumes in time at ~300-400 kb/sec. I have run this test on OS X (El Capitan) and Ubuntu 15.10. On Linux also virtual memory (address space) consumed at ~1 GB/sec rate! </p> <p> ifdef-ed part of code are used to run on valgrind and test that future's target objects are NOT leaked. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11951 Trac 1.4.3 snizovtsev@… Wed, 03 Feb 2016 10:54:25 GMT attachment set https://svn.boost.org/trac10/ticket/11951 https://svn.boost.org/trac10/ticket/11951 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">when_all.cc</span> </li> </ul> Ticket snizovtsev@… Wed, 03 Feb 2016 10:56:05 GMT <link>https://svn.boost.org/trac10/ticket/11951#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11951#comment:1</guid> <description> <p> Valgrind output: </p> <pre class="wiki">==3289== 5,760 bytes in 10 blocks are possibly lost in loss record 6 of 7 ==3289== at 0x4C2DB95: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==3289== by 0x40134B4: allocate_dtv (dl-tls.c:322) ==3289== by 0x40134B4: _dl_allocate_tls (dl-tls.c:544) ==3289== by 0x5BCE0D2: allocate_stack (allocatestack.c:588) ==3289== by 0x5BCE0D2: pthread_create@@GLIBC_2.2.5 (pthread_create.c:537) ==3289== by 0x504CE28: boost::thread::start_thread_noexcept() (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.60.0) ==3289== by 0x40D15D: boost::thread::start_thread() (thread.hpp:178) ==3289== by 0x4236E9: boost::thread::thread&lt;void (*)(boost::shared_ptr&lt;boost::detail::shared_state_base&gt;), boost::shared_ptr&lt;boost::detail::shared_state_base&gt; &gt;(void (*)(boost::shared_ptr&lt;boost::detail::shared_state_base&gt;), boost::shared_ptr&lt;boost::detail::shared_state_base&gt;, boost::disable_if&lt;boost::thread_detail::is_convertible&lt;void (*&amp;)(boost::shared_ptr&lt;boost::detail::shared_state_base&gt;), boost::thread_attributes&gt;, boost::thread::dummy*&gt;::type) (thread.hpp:393) ==3289== by 0x420233: boost::detail::future_when_all_vector_shared_state&lt;boost::future&lt;Int&gt; &gt;::init() (future.hpp:5211) ==3289== by 0x41B25E: boost::disable_if&lt;boost::is_future_type&lt;std::move_iterator&lt;__gnu_cxx::__normal_iterator&lt;boost::future&lt;Int&gt;*, std::vector&lt;boost::future&lt;Int&gt;, std::allocator&lt;boost::future&lt;Int&gt; &gt; &gt; &gt; &gt; &gt;, boost::future&lt;std::vector&lt;std::move_iterator&lt;__gnu_cxx::__normal_iterator&lt;boost::future&lt;Int&gt;*, std::vector&lt;boost::future&lt;Int&gt;, std::allocator&lt;boost::future&lt;Int&gt; &gt; &gt; &gt; &gt;::value_type, std::allocator&lt;std::move_iterator&lt;__gnu_cxx::__normal_iterator&lt;boost::future&lt;Int&gt;*, std::vector&lt;boost::future&lt;Int&gt;, std::allocator&lt;boost::future&lt;Int&gt; &gt; &gt; &gt; &gt;::value_type&gt; &gt; &gt; &gt;::type boost::when_all&lt;std::move_iterator&lt;__gnu_cxx::__normal_iterator&lt;boost::future&lt;Int&gt;*, std::vector&lt;boost::future&lt;Int&gt;, std::allocator&lt;boost::future&lt;Int&gt; &gt; &gt; &gt; &gt; &gt;(std::move_iterator&lt;__gnu_cxx::__normal_iterator&lt;boost::future&lt;Int&gt;*, std::vector&lt;boost::future&lt;Int&gt;, std::allocator&lt;boost::future&lt;Int&gt; &gt; &gt; &gt; &gt;, std::move_iterator&lt;__gnu_cxx::__normal_iterator&lt;boost::future&lt;Int&gt;*, std::vector&lt;boost::future&lt;Int&gt;, std::allocator&lt;boost::future&lt;Int&gt; &gt; &gt; &gt; &gt;) (future.hpp:5493) ==3289== by 0x4145ED: boost::future&lt;void&gt; iter&lt;Int, 2ul&gt;(int) (when_all.cc:85) ==3289== by 0x40B328: main (when_all.cc:99) </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 05 Feb 2016 07:24:13 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/11951#comment:2 https://svn.boost.org/trac10/ticket/11951#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Mon, 15 Aug 2016 18:19:47 GMT <link>https://svn.boost.org/trac10/ticket/11951#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11951#comment:3</guid> <description> <p> Sorry for been late. </p> <p> It seems that the source and the stack doesn't match. Could you reload them? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 15 Aug 2016 18:21:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11951#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11951#comment:4</guid> <description> <p> See also <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12220" title="#12220: Bugs: Memory leak in future::then() (closed: fixed)">#12220</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 19 Aug 2016 22:01:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11951#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11951#comment:5</guid> <description> <p> I should use a weak_ptr instead but for the time been I don't reach to make it working. Any help much appreciated. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 03 Sep 2016 15:20:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11951#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11951#comment:6</guid> <description> <p> I have committed </p> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/5450e98c6bd2515388de1d3d97431cf5374319e7"><span class="icon">​</span>https://github.com/boostorg/thread/commit/5450e98c6bd2515388de1d3d97431cf5374319e7</a> </p> <p> Please, could you tell me if this fixes the issue? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 03 Sep 2016 19:24:55 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/11951#comment:7 https://svn.boost.org/trac10/ticket/11951#comment:7 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.62.0</span> </li> </ul> Ticket viboes Tue, 06 Sep 2016 16:50:48 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11951#comment:8 https://svn.boost.org/trac10/ticket/11951#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket