Skip to content

Instantly share code, notes, and snippets.

@bakineggs
Created February 9, 2009 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bakineggs/60900 to your computer and use it in GitHub Desktop.
Save bakineggs/60900 to your computer and use it in GitHub Desktop.
// 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