Delete Array of Pointers
I have an array of pointers:
I have a problem cleaning them up...
The game crashes when closing down. In particular due to the last line of code:
for (int i = 0; i < 3; ++i)
But g_pTank is not allocated, only the elements in the array are, right?
It would help if you posted the code that allocates the memory.
Also remember to use delete  only when you've used new .
But since this is C++, you should probably be using smart pointers anyway.
Here was the code of initialisation - didnt realise I forgot to post it
What do you think now?
g_pTank = new Bitmap(hDC, IDB_TANK, g_hInstance);
g_pTank = new Bitmap(hDC, IDB_TANK2, g_hInstance);
g_pTank = new Bitmap(hDC, IDB_TANK3, g_hInstance);
You can use smart pointers. If not, then use delete on each element and not on the array itself.
Originally Posted by Elysia
In which case, you should use delete (without ) for the three array elements, and not at all for the array itself.
Or if you don't understand, the smart pointer takes ownership of the memory and frees it itself, freeing the burden from the programmer.