Skip to content

Instantly share code, notes, and snippets.

@sgulseth
Last active March 21, 2016 09:37
Show Gist options
  • Select an option

  • Save sgulseth/7bee0ba95ef042077a1a to your computer and use it in GitHub Desktop.

Select an option

Save sgulseth/7bee0ba95ef042077a1a to your computer and use it in GitHub Desktop.
// 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
@mdrobny
Copy link

mdrobny commented Mar 21, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment