[Boost-bugs] [Boost C++ Libraries] #10726: boost::lockfree::queue doesn't seem to free memory though destructors on every collection objects are invoked

Subject: [Boost-bugs] [Boost C++ Libraries] #10726: boost::lockfree::queue doesn't seem to free memory though destructors on every collection objects are invoked
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-10-31 11:10:46


#10726: boost::lockfree::queue doesn't seem to free memory though destructors on
every collection objects are invoked
----------------------------------+--------------------------
 Reporter: ableabhijeet@… | Owner: timblechmann
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: lockfree
  Version: Boost 1.56.0 | Severity: Problem
 Keywords: boost lockfree queue |
----------------------------------+--------------------------
 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.

 {{{
 #include <iostream>
 #include <Windows.h>
 #include <boost/thread/thread.hpp>
 #include <boost/lockfree/queue.hpp>

 using namespace std;
 using namespace boost;

 struct Record
 {
     char str[128];

     Record(const char* rec)
     {
         memset(this->str, 0, sizeof(this->str));
         strcpy_s(this->str, rec);
     }

     ~Record()
     {
         cout << "~Record " << this->str << endl;
     }

     Record& operator= (const Record& rec)
     {
         if (this == &rec)
         {
             return *this;
         }

         memset(this->str, 0, sizeof(this->str));
         strcpy_s(this->str, rec.str);
         return *this;
     }
 };

 typedef boost::lockfree::queue<Record*,
 boost::lockfree::fixed_sized<true>> 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 << "Record " << rec->str << endl;
                 delete rec;
             }
         };
     }
 };

 int _tmain(int argc, _TCHAR* argv[])
 {
     boost::thread* thread1, *thread2;

     MyClass myObj;

     thread1 = new boost::thread(boost::bind(&MyClass::FillThread, myObj));
     HANDLE threadHandle1 = thread1->native_handle();
     SetThreadPriority(threadHandle1, THREAD_PRIORITY_NORMAL);

     boost::this_thread::sleep(boost::posix_time::seconds(1));

     thread2 = new boost::thread(boost::bind(&MyClass::ProcessThread,
 myObj));
     HANDLE threadHandle2 = thread2->native_handle();
     SetThreadPriority(threadHandle2, THREAD_PRIORITY_NORMAL);

     thread1->join();
     thread2->join();

     return 0;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10726>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC