This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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