1. vector
1. 1 After vector is allocated, the memory it occupies is not freed until destructor is called, even if v.clear() is called.
To explicitly deallocate this piece of memory, use this trick
for (...; ...; ...) {
v.clear();
vector<int> temp();
v.swap(temp);
}
temp is on the stack, after the stack exits, the destruction function is called and thus the memory occupied by the v is freed
1. 2 It will consumes a lot of memory when use erase in vector, if the vector size is large
for(it = v.begin(); it != v.end(); ){
if (conditions)
v.erase(it);
else
++it;
}
It is better to use this function in linklist