title: Stack memory not released
body: <p>I have the following loop, which pops a C++ concurrent queue I have, from the implementation here. <a href="https://juanchopanzacpp.wordpress.com/2013/02/26/concurrent-queue-c11/" rel="nofollow">https://juanchopanzacpp.wordpress.com/2013/02/26/concurrent-queue-c11/</a></p>
  
  <pre><code>while (!interrupted)
  {
      pxData data = queue-&gt;pop(); 
      if (data.value == -1)
      { 
          break; // exit loop on terminating condition
       }
      usleep(7000); // stub to simulate processing
  }
  </code></pre>
  
  <p>I am looking at the memory history using System Monitor in CentOS7. 
  I'm trying to free up the memory taken up by the queue, after reading the value from the queue. However, as the following while loop runs, I don't see the memory usage going down. I've verified that the queue length does go down. </p>
  
  <p>It does go down, however, when -1 is encountered and the loop exits. (program is still running) But I can't have this, because where usleep is, I want to do some intensive processing. </p>
  
  <p><strong>Question</strong>: Why doesn't the memory occupied by data get free-ed? (according to System Monitor) Isn't the stack allocated memory supposed to be free-ed when the variable goes out of scope?</p>
  
  <p>The struct is defined as follows, and populated at the beginning of the program. </p>
  
  <pre><code>typedef struct pxData
  {
    float value; // -1 value terminates the loop
    float x, y, z;
    std::complex&lt;float&gt; valueData[65536];
  } pxData;
  </code></pre>
  
  <p>It's populated with ~10000 pxData, which roughly translates to 5GB. System only has ~8GB. 
  So it's important that the memory is free-ed up for doing other processing in the system. </p>