Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Hard to track when to delete pointer in large project
//We need to free the memory at the right step!
void foo(){
Dog* p = new Dog("Gunner");
//...
delete p;
//...
p->bark(); // p is a dangling pointer now -- undefined behavior
}// If we do not delete p, then we will have memory leak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment