title: Operator "delete" not return used memory
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5994543/problem-usage-memory-in-c">Problem usage memory in C</a>  </p>
  </blockquote>
  
  
  
  <p>I have problem: operator "delete" does not return allocated memory.</p>
  
  <p>Peace of code to illustrate how I use "delete" operator. Сertainly, before this code called  all pointers created with operator "new" at other parts of the program:</p>
  
  <pre><code>std::multimap&lt;std::string, Container*&gt;::iterator it;
  for ( it = MAPX.begin() ; it != MAPX.end(); )
  {
      Container* ptr_container = it-&gt;second;
  
      // delete every object at the container
      std::multimap&lt;unsigned int, TMB*&gt;::iterator it_tmb;
      for ( it_tmb = ptr_container-&gt;map_thumbs.begin() ; it_tmb != ptr_container-&gt;map_thumbs.end(); )
      {
          TMB* ptr_currentGlobalThumb = it_tmb-&gt;second;
  
          ptr_container-&gt;map_thumbs.erase( it_tmb++ ); // erase from map      
          delete ptr_currentGlobalThumb; // delete at the memmory
      }
  
  
      delete ptr_container; // lets delete empty container now
      MAPX.erase( it++ ); // and erase it from map
  }
  </code></pre>
  
  <p>Before I start this peace of code I look at my <code>top</code> and <code>ps aux</code> output at FreeBSD and see that program use 241M of memory: </p>
  
  <pre><code>ps: abrahab 21351  3.5  7.3 263108 246932  ??  S     3:19PM   1:50.94 program
  top: 21351 abrahab 8  -8    0   257M   241M biord   2   0:47  8.30% program
  </code></pre>
  
  <p>After cleaning process nothing changed! As program use 241M of RAM, so program continued to use memory (not deallocated). Why?</p>
  
  <p>After restart of program, I see that memory returned for system (of course): </p>
  
  <pre><code>abrahab 71595  0.0  5.0 185284 170360  ??  I     4:50PM   0:18.62 program 
  </code></pre>
  
  <p><strong>EDIT:</strong>
  1) So how can I control <strong>real memory usage</strong> of my program when its running?
  2) Seems that program crash(end without the .core file) when its begin to use ~1Gb of memory on 32bit FreeBSD - is it possible that FreeBSD "end" program that use too much memory?</p>