Skip to content

Instantly share code, notes, and snippets.

@jasonroelofs
Forked from bakineggs/scene.cpp
Created February 9, 2009 18:27
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 jasonroelofs/60903 to your computer and use it in GitHub Desktop.
Save jasonroelofs/60903 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