The memory remains attached to the vector. That isn't just likely either. It's required. In particular, if you were to add elements to the vector again after calling clear()
, the vector must not reallocate until you add more elements than the 1000 is it was previously sized to.
If you want to free the memory, the usual is to swap with an empty vector. C++11 also adds a shrink_to_fit
member function that's intended to provide roughly the same capability more directly, but it's non-binding (in other words, it's likely to release extra memory, but still not truly required to do so).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…