diff --git a/src/prevector.h b/src/prevector.h --- a/src/prevector.h +++ b/src/prevector.h @@ -475,6 +475,12 @@ iterator erase(iterator pos) { return erase(pos, pos + 1); } iterator erase(iterator first, iterator last) { + // Erase is not allowed to the change the object's capacity. That means + // that when starting with an indirectly allocated prevector with + // size and capacity > N, the result may be a still indirectly allocated + // prevector with size <= N and capacity > N. A shrink_to_fit() call is + // necessary to switch to the (more efficient) directly allocated + // representation (with capacity N and size <= N). iterator p = first; char *endp = (char *)&(*end()); if (!std::is_trivially_destructible::value) { diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -653,8 +653,9 @@ } void clear() { - // The default std::vector::clear() does not release memory. - CScriptBase().swap(*this); + // The default prevector::clear() does not release memory + CScriptBase::clear(); + shrink_to_fit(); } };