essential-js-design-patterns
essential-js-design-patterns copied to clipboard
question: design pattern to avoid memory leaks
Hi @addyosmani ,
Your design pattern book is awesome. I am working with nodejs and need some advice on scenarios like below:
Lets say i have a function that makes persistent tcp connection to say twitter and does all the parsing on that. Eg:
function addTwitter(somedata) {
var twit = new Twitter(somedata);
twit.on('twit', function(err,data) {
//do something here
// use somedata variable here.
}
}
addTwitter(somehandle);
addTwitter(anotherhandle);
so basically this addTwitter is used to make multiple connections to twitter server.
I am wondering if this style will leak memory. Also, If there is a better way of doing this.
I actually think there would be huge value in adding a section on memory leak patterns. Good suggestion. I've recently given a talk on a similar subject - slides here: https://speakerdeck.com/addyosmani/javascript-memory-management-masterclass and might be able to extract some of this info into a chapter in the future.
:+1: