Skip to content

Instantly share code, notes, and snippets.

@domiyanyue
Created August 10, 2020 21:01
Show Gist options
  • Save domiyanyue/949f373bac2067740bddb4e2511879e2 to your computer and use it in GitHub Desktop.
Save domiyanyue/949f373bac2067740bddb4e2511879e2 to your computer and use it in GitHub Desktop.
int mem_demo_static(){
A a;
return a.func();
// A's destructor is called automatically
}
int mem_demo_dynamic(){
A* a = new A;
return a->func();
// A's destructor is not called, memory leak!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment