I am trying to learn the best habits and practices in C++, particularly surrounding memory management. I have been spoiled on this front by using ARC in my iOS apps, and the built-in GC in Java, as well as a few other languages where GC is enabled.
I understand that you use
int intToDelete = 6;
delete should only be used with pointers which you allocated explicitly with
new, respectively. In particular, for every time you use
new, you should have a corresponding
delete. Similarly, each
new needs a corresponding
delete. You should never use either of these with variables for which you do not explicitly allocate memory. The compiler takes care of memory allocation (and deallocation) for all non-pointer variables.