I have a weird problem with vector in C++..
I created a vector and inserted 10000 integer values into it and have checked the memory utilization. It is 600 kb. But after i erased the vector, still my system monitor says the program uses 600 kb.
Can anyone explain why the memory is not getting freed even after i erase the vector
Note: I have used all the methods for deletion(erase,pop_front,pop_back,clear…Even then I have the same problem)
Thanks and regards…:)
The only way to really get rid off unused memory in a
std::vector<>pre C++11 is to swap it with an empty vector:vector<int>().swap(myvec). In C++11 you have a member functionshrink_to_fitwhich often is implemented as the swap idiom just mentioned.