When to delete objects from the heap in C++?
<p>I am a little confused when/how to delete objects from the heap in C++.</p>

<p>When:</p>

<p>If you are executing a program which is relatively short, computes something and then passes standard output to the console is it worth destroying all your objects just after the console has output the result or would the program destroy automatically upon exiting? In the case of large programs I presume it would definitely be better practice to try and work out when you no longer need any of your objects?</p>

<p>How:</p>

<p>If I have a vector containing pointers to MyClass objects, once I am finished with the vector (and MyClass objects) how do I write a destructor that can destroy all the MyClass objects pointed to by the vector? (Obviously I will need to destroy the vector too).</p>
