The clear method will actually call destructors. However, your vector stores pointers, and the destructor for pointers is trivial no-op. It does not call delete .
Therefore, simply calling clear will not free up memory for all int objects that you allocated with new . You need to delete them.
If you use a smart pointer instead of a regular pointer, then objects with a pointer will be freed at the appropriate time without having to do anything special.
source share