If I have a vector<string*> *vect or a map<pair<string*, int*>, string*> *map,
how to clean up everything (including all object the vector/map contains)?
(Everything (vector, map, contents, string, ints) is allocated with new)
Is this enough:
delete vect;
delete map;
No, you must iterate through the
vector/map, remove and delete its items one by one (which, as @SB pointed out, may require disposing of their members recursively).(You could get away by simply deleting the items, if you are absolutely sure no one will access the vector elements anymore before the vector gets deleted – but it is still safer to remove each item before deleting it. This ensures program correctness at any point, eliminating the possibility for subtle bugs and easing maintenance in the long term.)
By the way this is one of the reasons why it is recommended to store smart pointers in collections, instead of raw pointers.