Skip to content

Instantly share code, notes, and snippets.

@awerlang
Created December 6, 2017 14:56
Show Gist options
  • Save awerlang/271012319257ae664a8076d01300fbee to your computer and use it in GitHub Desktop.
Save awerlang/271012319257ae664a8076d01300fbee to your computer and use it in GitHub Desktop.
memory leaks - #nodejspoa
// não precisa de um objeto ou estado a ser guardado
(function () {
function callMeMaybe() {
setTimeout(() => {
console.log('Node.js POA @ Umbler ' + x);
callMeMaybe();
}, 1000);
}
callMeMaybe();
})();
// ainda há memory leak?
// remover var self = this, já que a função que acessa callMeMaybe já é uma arrow
var myObj = {
callMeMaybe: function () {
setTimeout(() => {
console.log(‘Node.js POA @ Umbler’);
this.callMeMaybe();
}, 1000);
}
};
myObj.callMeMaybe();
myObj = null;
// ainda há memory leak?
var myObj = {
callMeMaybe: {
var self = this;
var val = setTimeout(() => {
console.log(‘Node.js POA @ Umbler’);
self.callMeMaybe();
}, 1000);
}
};
myObj.callMeMaybe();
myObj = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment