Not sure what that code does, but there is no garbage collection in C++. Memory allocated on the stack is freed when it goes out of scope. Memory on the heap (using new) remains until you call delete.