Boost C++ Libraries: Ticket #10726: boost::lockfree::queue doesn't seem to free memory though destructors on every collection objects are invoked https://svn.boost.org/trac10/ticket/10726 <p> The problem here is, boost::lockfree::queue doesn't free memory once it is allocated. Why freelist nodes are not returned to OS? destructors on individual collection objects are invoked. </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;Windows.h&gt; #include &lt;boost/thread/thread.hpp&gt; #include &lt;boost/lockfree/queue.hpp&gt; using namespace std; using namespace boost; struct Record { char str[128]; Record(const char* rec) { memset(this-&gt;str, 0, sizeof(this-&gt;str)); strcpy_s(this-&gt;str, rec); } ~Record() { cout &lt;&lt; "~Record " &lt;&lt; this-&gt;str &lt;&lt; endl; } Record&amp; operator= (const Record&amp; rec) { if (this == &amp;rec) { return *this; } memset(this-&gt;str, 0, sizeof(this-&gt;str)); strcpy_s(this-&gt;str, rec.str); return *this; } }; typedef boost::lockfree::queue&lt;Record*, boost::lockfree::fixed_sized&lt;true&gt;&gt; RecordsQueue; RecordsQueue Records(10000); class MyClass { public: void FillThread() { int i = 0; while (true) { Record *rec = new Record(to_string(i).c_str()); Records.push(rec); i++; }; } void ProcessThread() { while (true) { Record *rec; Records.pop(rec); { cout &lt;&lt; "Record " &lt;&lt; rec-&gt;str &lt;&lt; endl; delete rec; } }; } }; int _tmain(int argc, _TCHAR* argv[]) { boost::thread* thread1, *thread2; MyClass myObj; thread1 = new boost::thread(boost::bind(&amp;MyClass::FillThread, myObj)); HANDLE threadHandle1 = thread1-&gt;native_handle(); SetThreadPriority(threadHandle1, THREAD_PRIORITY_NORMAL); boost::this_thread::sleep(boost::posix_time::seconds(1)); thread2 = new boost::thread(boost::bind(&amp;MyClass::ProcessThread, myObj)); HANDLE threadHandle2 = thread2-&gt;native_handle(); SetThreadPriority(threadHandle2, THREAD_PRIORITY_NORMAL); thread1-&gt;join(); thread2-&gt;join(); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10726 Trac 1.4.3 timblechmann Fri, 31 Oct 2014 11:26:51 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10726#comment:1 https://svn.boost.org/trac10/ticket/10726#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> <a href="http://www.boost.org/doc/libs/1_56_0/doc/html/lockfree/rationale.html#lockfree.rationale.memory_management">http://www.boost.org/doc/libs/1_56_0/doc/html/lockfree/rationale.html#lockfree.rationale.memory_management</a> </p> Ticket anonymous Fri, 31 Oct 2014 11:46:05 GMT <link>https://svn.boost.org/trac10/ticket/10726#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10726#comment:2</guid> <description> <p> It is okay to reuse the free list block. So when 10000 nodes are allocated, program will continue to iterate from 1 to 10000 nodes. I don't understand Why memory keeps on increasing, memory usage is in GBs!.... I have lockfree::queue of fixed_sized 10000. </p> </description> <category>Ticket</category> </item> </channel> </rss>