title: Memory leak with dynamic allocation inside a function
body: <p>I am learning C++ in an online class, currently discussing pointers and memory leaks.</p>
  
  <p>In the course it was told that when a function body ends all local variables are destroyed (in reverse order to which they were declared).</p>
  
  <p>What i'm trying to understand is whether this code leaks memory or not:</p>
  
  <pre><code>void function()
  {
      TestClass *p = new TestClass();
  }
  </code></pre>
  
  <p>As it seems, it does, but i am not sure why the pointer "p" is not being dereferenced to its heap address and the data there is deleted once the function scope exits.</p>