The C++ standard seems to make no statement regarding side-effects on capacity by either
resize(n), with n < size(), or clear().>
As i checked for gcc (mingw) the only way to free vector capacity is what mattnewport says. Swaping it with other teporary vector. This code makes it for gcc.
template void shrinkContainer(C &container) {
if (container.size() != container.capacity()) {
C tmp = container;
swap(container, tmp);
}
//container.size() == container.capacity()
}