one other thing to keep track of is when you have an array of objects.
The rule of thumb is to always call delete the same way you called new
- Code: Select all
MyObj* myobj = new MyObj();
MyObj* myobj_array = new MyObj;
delete  myobj_array;
5 lines; 4 keywds; 1 nums; 14 ops; 0 strs; 0 coms Syntactic Coloring v0.4 - Dan East
notice the second example has empty brackets after delete. This is to ensure you clean up all elements of the array. If you don't include the brackets you will only be deleting the first element of the array and the other elements will still be hanging around