There are a growing number of tools for debugging and profiling memory
usage in Node.JS applications, but there is still a need for a
platform-independent native module that requires no special
instrumentation. This module attempts to satisfy that need.

The best way to evaluate your memory footprint is to look at heap
usage right aver V8 performs garbage collection. memwatch does
exactly this - it checks heap usage only after GC to give you a stable
baseline of your actual memory usage.

When V8 performs a garbage collection (technically, we're talking
about a full GC with heap compaction), memwatch will emit a stats
event.

memwatch.on('stats',function(stats){...});

The stats data will look something like this:

{

"num_full_gc":17,

"num_inc_gc":8,

"heap_compactions":8,

"estimated_base":2592568,

"current_base":2592568,

"min":2499912,

"max":2592568,

"usage_trend":0

}

estimated_base and usage_trend are tracked over time. If usage
trend is consistently positive, it indicates that your base heap size
is continuously growing and you might have a leak.

V8 has its own idea of when it's best to perform a GC, and under a
heavy load, it may defer this action for some time. To aid in
speedier debugging, memwatch provides a gc() method to force V8 to
do a full GC and heap compaction.