Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created July 12, 2019 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/2bebed44350acdcae5323c639f0e6c64 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/2bebed44350acdcae5323c639f0e6c64 to your computer and use it in GitHub Desktop.
//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