title: Is there a reason to call delete in C++ when a program is exiting anyway?
body: <p>In my C++ <code>main</code> function, for example, if I had a pointer to a variable which uses heap memory (as opposed to stack memory) - is this automatically deallocated after my application exits? I would assume so.</p>
  <p>Even so, is it good practice to always delete heap allocations even if you think they will never be used in a situation where the memory is automatically deallocated on exit?</p>
  <p>For example, is there any point in doing this?</p>
  <pre><code>int main(...)
  {
      A* a = new A();
      a-&gt;DoSomething();
      delete a;
      return 0;
  }
  </code></pre>
  <p>I was thinking <em>maybe</em> in case I refactor (or someone else refactors) that code and puts it elsewhere in the application, where <code>delete</code> is really necessary.</p>
  <p>As well as the answer by Brian R. Bondy (which talks specifically about the implications in C++), Paul Tomblin also has a <a href="https://stackoverflow.com/questions/654754/what-really-happens-when-you-dont-free-after-malloc/654766#654766">good answer to a C specific question</a>, which also talks about the C++ destructor.</p>