Created
December 24, 2018 07:34
-
-
Save Bloofer/1c69fc17b62cb06a3f6ac3dac5b0a39e to your computer and use it in GitHub Desktop.
var scope example
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
// 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