Created
August 10, 2020 21:01
-
-
Save domiyanyue/949f373bac2067740bddb4e2511879e2 to your computer and use it in GitHub Desktop.
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
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