Last active
March 21, 2016 09:37
-
-
Save sgulseth/7bee0ba95ef042077a1a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Scenario 1: | |
| function someFunction() { | |
| return new Promise(function (resolve, reject) { | |
| const someVariable = 1; | |
| resolve(someVariable); | |
| }); | |
| } | |
| callIt = someFunction() | |
| // the variable 'someVariable' will be cleaned by garbage collector | |
| // Scenario 2: | |
| function someFunction() { | |
| const someVariable = 1; | |
| return new Promise(function (resolve, reject) { | |
| resolve(someVariable); | |
| }) | |
| } | |
| callIt = someFunction(); | |
| // the variable 'someVariable' can't be cleaned by garbage collector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see this and I agree it changes how the gc may work and scenario 1 is of course better but it's an easy example. An async chain of actions is more difficult and should not be resolved by wrapping everything in Promise callback, that's my opinion :)
the variable 'someVariable' can't be cleaned by garbage collector- until Promise is fulfilled, is that true?