title: Why is memory still accessible after std::map::clear() is called?
body: <p>I am observing strange behaviour of std::map::clear(). This method is supposed to call element's destructor when called, however memory is still accessible after call to clear().</p>
  
  <p>For example:</p>
  
  <pre><code>struct A
  {
    ~A() { x = 0; }
    int x;
  };
  
  int main( void )
  {
    std::map&lt; int, A * &gt; my_map;
    A *a = new A();
    a-&gt;x = 5;
    my_map.insert( std::make_pair&lt; int, *A &gt;( 0, a ) );
  
    // addresses will be the same, will print 5
    std::cout &lt;&lt; a &lt;&lt; " " &lt;&lt; my_map[0] &lt;&lt; " " &lt;&lt; my_map[0]-&gt;x &lt;&lt; std::endl;
  
    my_map.clear();
  
    // will be 0
    std::cout &lt;&lt; a-&gt;x &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>The question is, why is variable <code>a</code> still accessible after its destructor was called by map::clear()? Do I need to write <code>delete a;</code> after calling <code>my_map.clear()</code> or is it safe to overwrite the contents of <code>a</code>?</p>
  
  <p>Thanks in advance for your help,
  sneg</p>