title: Leaking memory when assigning new value to variable?
body: <p>Yes, I'm one of those fellows that is learning C++ coming from Java, being spoiled with an automatic garbage collector. There's a particular situation where I'm wondering whether I'm leaking memory or not. Let's consider in C++:</p>
  
  <pre><code>bool *test = new bool(false);
  test = new bool(true);
  delete test;
  </code></pre>
  
  <p>Am I leaking memory here? Or should I first call <code>delete</code> before assigning a new value? Like this:</p>
  
  <pre><code>bool *test = new bool(false);
  delete test;
  test = new bool(true);
  delete test;
  </code></pre>
  
  <p>My gut feeling tells me the first is right, as the pointer <code>test</code> points at the same address in memory, and assigning a new value to its variable, will not change this address. Or does the <code>new</code> operator allocate a different address in memory? Can anyone give me a clue, or did I get it wrong all together?</p>