-
-
Save jasonroelofs/60903 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
// leaks memory because a copy of the value of scene is returned and the pointer is never deleted | |
Image Scene::draw() const { | |
Image scene = *(new Image()); | |
// build the scene | |
return *scene; | |
} | |
// doesn't leak memory, but is ugly | |
Image Scene::draw() const { | |
Image *tmp = new Image(); | |
Image scene = *tmp; | |
delete tmp; | |
// build the scene | |
return scene; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment