I make a tiny experiment, code is as following :
vector<char> *p = new vector<char>[1024];
for (size_t i = 0; i < 1024; i++)
{
(*p++).resize(1024 * 1024);//alloc 1 G memory
}
sleep(5);
cout << "start to clear" << endl;
for (size_t i = 0; i < 1024; i++)
{
vector<char> tmp;
tmp.swap(*p++);
}
delete [] p;
cout << "clear over!" << endl;
sleep (5);
//here, the memory is still 1G, why ? thank you very much.