Q: How to clear extra capacity of vector?

A: Use the shrink-to-fit technique.
Code:
std::vector<int> myvector;
myvector.reserve(10000);
//use vector
//don't need extra capacity?
//clear it using shrink-to-fit technique:
std::vector<int>(myvector).swap(myvector);
If you want to clear it all (no elements required but the vector lives because of scope), do this:
Code:
std::vector<int>().swap(myvector);
For more information on this please refer the following link: