title: String vector still reachable
body: <p>I have this example code for string vector:</p>
  
  <pre><code>vector&lt;string&gt; strings;
  strings.push_back(argv[0]);
  cout &lt;&lt; strings[0] &lt;&lt; endl;
  strings.clear();
  
  exit(0);
  </code></pre>
  
  <p>But valgrind says:</p>
  
  <pre><code>==26012== HEAP SUMMARY:
  ==26012==     in use at exit: 8 bytes in 1 blocks
  ==26012==   total heap usage: 2 allocs, 1 frees, 41 bytes allocated
  ==26012== 
  ==26012== 8 bytes in 1 blocks are still reachable in loss record 1 of 1
  ==26012==    at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==26012==    by 0x401DCF: __gnu_cxx::new_allocator&lt;std::string&gt;::allocate(unsigned long, void const*) (new_allocator.h:92)
  ==26012==    by 0x401BD8: std::_Vector_base&lt;std::string, std::allocator&lt;std::string&gt; &gt;::_M_allocate(unsigned long) (in /home/nich/IPK/2/client)
  ==26012==    by 0x401706: std::vector&lt;std::string, std::allocator&lt;std::string&gt; &gt;::_M_insert_aux(__gnu_cxx::__normal_iterator&lt;std::string*, std::vector&lt;std::string, std::allocator&lt;std::string&gt; &gt; &gt;, std::string const&amp;) (vector.tcc:327)
  ==26012==    by 0x401421: std::vector&lt;std::string, std::allocator&lt;std::string&gt; &gt;::push_back(std::string const&amp;) (stl_vector.h:834)
  ==26012==    by 0x401102: main (client.cc:130)
  ==26012== 
  ==26012== LEAK SUMMARY:
  ==26012==    definitely lost: 0 bytes in 0 blocks
  ==26012==    indirectly lost: 0 bytes in 0 blocks
  ==26012==      possibly lost: 0 bytes in 0 blocks
  ==26012==    still reachable: 8 bytes in 1 blocks
  ==26012==         suppressed: 0 bytes in 0 blocks
  </code></pre>
  
  <p>What I am doing wrong? String::clear method should call destructor on string shouldn't?
  Anyway I tried alternative way with pointers.</p>
  
  <pre><code>vector&lt;string*&gt; strings;
  strings.push_back(new string(argv[0]));
  cout &lt;&lt; *(strings[0]) &lt;&lt; endl;
  delete strings[0];
  strings.clear();
  
  exit(0);
  </code></pre>
  
  <p>Valgrind:</p>
  
  <pre><code>==10177== HEAP SUMMARY:
  ==10177==     in use at exit: 8 bytes in 1 blocks
  ==10177==   total heap usage: 3 allocs, 2 frees, 49 bytes allocated
  ==10177== 
  ==10177== 8 bytes in 1 blocks are still reachable in loss record 1 of 1
  ==10177==    at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==10177==    by 0x401CF9: __gnu_cxx::new_allocator&lt;std::string*&gt;::allocate(unsigned long, void const*) (new_allocator.h:92)
  ==10177==    by 0x401B5C: std::_Vector_base&lt;std::string*, std::allocator&lt;std::string*&gt; &gt;::_M_allocate(unsigned long) (in /home/nich/IPK/2/client)
  ==10177==    by 0x4016EA: std::vector&lt;std::string*, std::allocator&lt;std::string*&gt; &gt;::_M_insert_aux(__gnu_cxx::__normal_iterator&lt;std::string**, std::vector&lt;std::string*, std::allocator&lt;std::string*&gt; &gt; &gt;, std::string* const&amp;) (vector.tcc:327)
  ==10177==    by 0x4013F1: std::vector&lt;std::string*, std::allocator&lt;std::string*&gt; &gt;::push_back(std::string* const&amp;) (stl_vector.h:834)
  ==10177==    by 0x4010C4: main (client.cc:130)
  ==10177== 
  ==10177== LEAK SUMMARY:
  ==10177==    definitely lost: 0 bytes in 0 blocks
  ==10177==    indirectly lost: 0 bytes in 0 blocks
  ==10177==      possibly lost: 0 bytes in 0 blocks
  ==10177==    still reachable: 8 bytes in 1 blocks
  ==10177==         suppressed: 0 bytes in 0 blocks
  </code></pre>
  
  <p>But still same problem. Can you please tell me how I should parse arguments from *argv[] to vector string without still reachable bytes?</p>