title: std::string causing memory leaks
body: <p>I am running into a situation where my application is having memory leaks. After running valgrind, it looks as if I am getting a memory leak related to a std::string:</p>
  
  <pre><code> ==20274== 34 bytes in 1 blocks are definitely lost in loss record 34 of 140
   ==20274==    at 0x4C29DB5: operator new(unsigned long) (vg_replace_malloc.c:332)
   ==20274==    by 0x7F843C8: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator&lt;char&gt; const&amp;) (in /usr/lib64/libstdc++.so.6.0.13)
   ==20274==    by 0x7F84DE4: ??? (in /usr/lib64/libstdc++.so.6.0.13)
   ==20274==    by 0x7F84F32: std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(char const*, std::allocator&lt;char&gt; const&amp;) (in /usr/lib64/libstdc++.so.6.0.13)
   ==20274==    by 0xA50CC71: __static_initialization_and_destruction_0(int, int) (filename.cpp:22)
   ==20274==    by 0xA50D03F: _GLOBAL__sub_I_filename.cpp (filename.cpp:112)
   ==20274==    by 0x400E9CE: _dl_init (in /lib64/ld-2.12.so)
   ==20274==    by 0x4000B69: ??? (in /lib64/ld-2.12.so)
  </code></pre>
  
  <p>The code in question is:</p>
  
  <p>in filename.h:</p>
  
  <pre><code> extern std::string aString;
  </code></pre>
  
  <p>in filename.cpp:</p>
  
  <pre><code> std::string aString = "a string";
  </code></pre>
  
  <p>Also worth note, this is in a separate namespace i.e.</p>
  
  <pre><code> namespace aNamespace {
        //...
        std::string aString; // in extern in .h
        //...
   }
  </code></pre>
  
  <p>Every place in code, it is (of course) referenced as:</p>
  
  <pre><code> aNamespace::aString;
  </code></pre>
  
  <p>And, from what I can tell, it is never reset, and is used either as a constant reference, or to initialize another string.</p>
  
  <p>Can there ever be a situation where std::string would give memory leaks?</p>
  
  <p>edit:</p>
  
  <p>A related portion of the valgrind output:</p>
  
  <pre><code> ==20274==    by 0x400EFBB: _dl_fini (in /lib64/ld-2.12.so)
   ==20274==    by 0x88DAA01: exit (in /lib64/libc-2.12.so)
   ==20274==    by 0x88C3D26: (below main) (in /lib64/libc-2.12.so)
  </code></pre>
  
  <p>Is this making an exit call? Is it the standard exit(0)?</p>