title: Issues with c++ thread memory leak on a simple thread when using join?
body: <p>I've written a program that features a main loop that kicks off threads at about 60 Hz.  I'm using std::thread to kick off the threads and I've played around a bit with join() and detach(), and for now I'm just using join until I figure out how to deal with this memory leak.</p>
  
  <p>I've found that even with a very simple thread, with a very simple task, joined immediately and subsequently deleted immediately, when I view the executable in Task Manager, I still see the memory gradually increase.  When I comment out those three lines of code, the memory usage remains stable.</p>
  
  <p>In essence, here's a stripped-down version of the code, pointing out those three lines in question:</p>
  
  <pre><code>void PrintStuff()
  {
      cout &lt;&lt; "Hi!\n";
  }
  
  void MainLoop::RunMainLoop()
  {
      // Variable Definitions
      thread *LoopThread;
  
      ...
  
      while(true){
  
      ...
  
         if (SixtyHz[CycleCounter]){
         //Simplified for readability, but runs at 60 Hz
  
              /*********************************************
              * These three lines right here.
              * If I comment these out, the memory usage 
              * is stable!
              *********************************************/
              LoopThread = new thread{PrintStuff};
              LoopThread-&gt;join();
              delete LoopThread;
  
         }
  
         ...
  
         //Increment CycleCounter with appropriate modulo arithmetic
         CycleCounter = ...
      }
  }
  </code></pre>
  
  <p>I'm using Code::Blocks with MinGW-w64, if that makes a difference.</p>
  
  <p>Is std::thread just not up to the task?  Or is there anything I should be doing to reclaim those resources?  What gives?  Those lines are as simple as I could think to make them, and still I see a memory leak.  Any suggestions are much appreciated.</p>