On Sun, Nov 18, 2012 at 11:21 AM, Felix E. Klee <[email protected]> wrote:
> How do I find out if (not where) there is a memory leak in an app?
>
> Background: I am using Socket.IO for client/server communication, and I
> want to make sure that server side resources are properly cleaned up
> when a connection is closed (`disconnect` event). Memory usage should be
> proportional (plus a constant) to the number of connections. It should
> not increase when reloading the app in the browser.

A quick and fairly reliable approach is to start node with --expose-gc
and call gc() every few seconds, like so:

  $ cat test.js
  if (typeof gc === 'function') setInterval(gc, 5000);
  require('./main.js'); // your main application

  $ node --expose-gc test.js

Keep an eye on RSS.  If your application is at equilibrium but RSS
keeps growing indefinitely, chances are good there is a memory leak.

The reason that you need to call gc() is that the garbage collector is
lazy.  It won't collect garbage until it's forced by sheer memory
pressure - and even then it may opt to grow the heap, not sweep it.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to