title: Memory leak when using std::vector with class elements
body: <p>I have following problem:</p>
  
  <p>When I use std::vector with built-ins i don't get a memory but if I use classes I get memory leak. To illustrate:</p>
  
  <pre><code>//No leak
  std::vector&lt;double&gt;* vecPtr1=new std::vector&lt;double&gt;();
  //add some elements
  delete vecPtr1;
  
  //Leaks some memory but not all
  std::vector&lt;SomeClass&gt;* vecPtr2=new std::vector&lt;SomeClass&gt;();
  //add some elements with vecPtr2-&gt;push_back(SomeClass());
  delete vecPtr2;
  </code></pre>
  
  <p>As far as I understand it delete should call the destructor of std::vector which should in turn call the destructor of SomeClass -> no leak. I have invested some thought and testing into this and the same behaviour happens if I use std::vector in a scope such as here:</p>
  
  <pre><code>{
    std::vector&lt;SomeClass&gt; vector;
    //add elements as before
  }
  //memory is still used here
  </code></pre>
  
  <p>I'm using gcc 4.6.1 under Ubuntu 11.10. Is something amiss in my library or do I have a misconception how std::vector destructs elements?</p>
  
  <p>For clarification my complete code with SomeClass replaced with std::pair (yes I know some parts are hacked but it's just an example):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;utility&gt;
  
  int main()
  {
      std::string inString;
      std::cout&lt;&lt;"Started"&lt;&lt;std::endl;
      //wait
      std::cin&gt;&gt;inString;
      {
          //assign vector
          std::vector&lt;std::pair&lt;std::string,unsigned int&gt; &gt; vec=std::vector&lt;std::pair&lt;std::string,unsigned int&gt; &gt;();
          //push elements
          for(unsigned int i=0;i&lt;1e7;++i)
          {
              vec.push_back(std::pair&lt;std::string,unsigned int&gt;("something",i));
          }
          std::cout&lt;&lt;"Created vector with capacity: "&lt;&lt;vec.capacity()&lt;&lt;std::endl;
          //wait
          std::cin&gt;&gt;inString;
      }
      //vec should go out of scope but not all memory gets freed
      std::cout&lt;&lt;"Deleted vector"&lt;&lt;std::endl;
      //wait
      std::cin&gt;&gt;inString;
      std::cout&lt;&lt;"Shutting down"&lt;&lt;std::endl;
  
      return 0;
  }
  </code></pre>