essential-js-design-patterns icon indicating copy to clipboard operation
essential-js-design-patterns copied to clipboard

question: design pattern to avoid memory leaks

Open chirag04 opened this issue 12 years ago • 2 comments

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.

chirag04 avatar Jul 15 '13 07:07 chirag04

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.

addyosmani avatar Aug 31 '14 12:08 addyosmani

:+1:

chirag04 avatar Sep 01 '14 07:09 chirag04