Consider the following code snippet:
std::vector<int> v;
v.reserve(100);
v.insert(v.end(), 100, 5);
v.erase(v.begin(), v.end());
std::cout << v.capacity << std::endl;
This prints out 100. Does it mean that vector still holds the 100 memory locations? Is it required to call reserve(0) after calling erase(begin,end) on a vector, to relinquish all space held by the vector?
You are looking for the (in)famous swap trick:
See here for backgrounder
How to downsize std::vector?