Actually, the vector will automatically free its contents whenever if goes out of scope, regardless of being stack allocated or not.
Untrue, a non-stack-allocated vector (one which uses a "new" keyword) will remain in memory after you exit the function, unless you call delete. Calling clear() is not enough in this case, as the vector will shrink, but will still leak some memory. But this is not the case in the original code, since there the vector is stack allocated.
stack allocated:
std::vector<int> tempVec;
non-stack allocated:
void foo(){
std::vector<int> *tempVec=new std::vector<int>();
...
delete tempVec; //correct way to release memory
//temvec->clear() is not enough and not necessary. It will only clear the vector contents, and will leave some garbage in memory
}