Skip to content

Instantly share code, notes, and snippets.

@spadgos
Created March 3, 2014 09:20
Show Gist options
  • Save spadgos/9321318 to your computer and use it in GitHub Desktop.
Save spadgos/9321318 to your computer and use it in GitHub Desktop.
Promises causing memory leaks
function bad() {
var promise = somethingAsync();
promise.finally(function () {
logSomeThings();
});
promise = promise.then(function (result) {
return transform(result);
});
return promise;
}
function good() {
var promise = somethingAsync();
promise = promise.finally(function () { // <-- only changed line
logSomeThings();
});
promise = promise.then(function (result) {
return transform(result);
});
return promise;
}
@spadgos
Copy link
Author

spadgos commented Mar 3, 2014

@kriskowal: having some difficulty repro'ing the error right now (the original leak was very slow and was only visible under production load -- fun!). I'll trying boiling it down to the raw test case above and update tomorrow.

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