title: Why is std::string/std::map not encouraged to be created on the heap?
body: <p>I have noticed on multiple questions, C++ experts asking that std::string/std::map/etc. should not be created with the 'new' keyword (newbie to C++, if it wasn't obvious).</p>
  
  <p>So, if my understanding is correct this would not create it on the heap but on the stack. This would mean that the moment the function goes out of scope, the object would disappear, but I believe that is not the case and my understanding is wrong.</p>
  
  <p>Is this because the underlying template instantiates it on the heap and manages it using an auto_ptr, so that it doesn't cause a memory leak? Does this apply for all stl classes?</p>
  
  <p>Also, a follow up question is what should be the approach to create objects that are inserted in maps? Should they be allocated on the heap (if they are valuable out of the scope of the function)?</p>
  
  <p>EDIT:</p>
  
  <p>I do understand the difference between heap and stack and the reasons for using each (I probably was not clear about this). </p>
  
  <p>The reason I ask for this is it seems unnatural, to just instantiate an object on the stack for an object I'd like to keep around. But, I guess this is just how the syntax looks like.</p>
  
  <p>This means, I feel like I'm having something on the stack when I write,</p>
  
  <pre><code>std::map&lt;int,int&gt; mymap;
  </code></pre>
  
  <p>instead of, </p>
  
  <pre><code>std::map&lt;int,int&gt; *mymap = new std::map&lt;int,int&gt;;
  </code></pre>
  
  <p>I'm also wondering about the impact of this on the memory. Since now the memory is cleaned up by this implementation itself, is it analogous to garbage collection in Java? Is there an implied performance impact when using an stl object?</p>