Skip to content

Instantly share code, notes, and snippets.

@Bloofer
Created December 24, 2018 07:34
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 Bloofer/1c69fc17b62cb06a3f6ac3dac5b0a39e to your computer and use it in GitHub Desktop.
Save Bloofer/1c69fc17b62cb06a3f6ac3dac5b0a39e to your computer and use it in GitHub Desktop.
var scope example
// Good idea
for (int i = 0; i < 15; ++i)
{
MyObject obj(i);
// do something with obj
}
// Bad Idea
MyObject obj; // meaningless object initialization
for (int i = 0; i < 15; ++i)
{
obj = MyObject(i); // unnecessary assignment operation
// do something with obj
}
// obj is still taking up memory for no reason
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment