Created
December 6, 2017 14:56
-
-
Save awerlang/271012319257ae664a8076d01300fbee to your computer and use it in GitHub Desktop.
memory leaks - #nodejspoa
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
// 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? |
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
// 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? |
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
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