{"_id":"strong-memwatch","_rev":"64-26609f37454625d53f8b47754a5a62ea","name":"strong-memwatch","dist-tags":{"latest":"0.2.3"},"versions":{"0.2.3":{"name":"strong-memwatch","version":"0.2.3","author":{"url":"http://lloyd.io","name":"Lloyd Hilaiel"},"_id":"strong-memwatch@0.2.3","maintainers":[{"name":"bnoordhuis","email":"info@bnoordhuis.nl"}],"contributors":[{"url":"http://strongloop.com/","name":"Ben Noordhuis","email":"ben@strongloop.com"},{"url":"@jedp","name":"Jed Parsons"},{"url":"@jhaynie","name":"Jeff Haynie"},{"url":"@jmatthewsr-ms","name":"Justin Matthews"}],"homepage":"https://github.com/strongloop/node-memwatch","bugs":{"url":"https://github.com/strongloop/node-memwatch/issues"},"dist":{"shasum":"7898908c544ef8c626fb1e5a121eb9e9bcd7e6a4","tarball":"https://registry.npmjs.org/strong-memwatch/-/strong-memwatch-0.2.3.tgz","integrity":"sha512-+emXuBT/DmG1ckXELHxYYeiq9BBs5fU3iaAbGCLHpAFOWTPN18PAUajRPjCto0FboHpleU4q/VCLXQfTh9ZeFA==","signatures":[{"sig":"MEYCIQDbuTdwwVj6KCZ2Gk1qHcgBSkJok842N+4aaMcqa/T7gQIhAIn6Tk9FFa8FD3HvkTHXtQqBG0JNvcaOjtUGygtjpxaO","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"include.js","_from":".","engines":{"node":">= 0.6.0"},"gypfile":true,"scripts":{"test":"mocha tests","install":"node-gyp rebuild"},"_npmUser":{"name":"bnoordhuis","email":"info@bnoordhuis.nl"},"licenses":[{"type":"wtfpl"}],"repository":{"url":"https://github.com/strongloop/node-memwatch.git","type":"git"},"_npmVersion":"1.3.24","description":"Keep an eye on your memory usage, and discover and isolate leaks.","directories":{},"devDependencies":{"mocha":"1.2.2","should":"0.6.3","node-gyp":"0.5.7"}}},"time":{"created":"2014-01-24T20:23:30.869Z","modified":"2026-04-14T15:10:48.658Z","0.2.3":"2014-01-24T20:23:30.869Z"},"bugs":{"url":"https://github.com/strongloop/node-memwatch/issues"},"author":{"url":"http://lloyd.io","name":"Lloyd Hilaiel"},"homepage":"https://github.com/strongloop/node-memwatch","repository":{"url":"https://github.com/strongloop/node-memwatch.git","type":"git"},"description":"Keep an eye on your memory usage, and discover and isolate leaks.","contributors":[{"url":"http://strongloop.com/","name":"Ben Noordhuis","email":"ben@strongloop.com"},{"url":"@jedp","name":"Jed Parsons"},{"url":"@jhaynie","name":"Jeff Haynie"},{"url":"@jmatthewsr-ms","name":"Justin Matthews"}],"maintainers":[],"readme":"`node-memwatch`: Leak Detection and Heap Diffing for Node.JS\n============================================================\n\n[![Build Status](https://secure.travis-ci.org/lloyd/node-memwatch.png)](http://travis-ci.org/lloyd/node-memwatch)\n\n`node-memwatch` is here to help you detect and find memory leaks in\nNode.JS code.  It provides:\n\n- A `leak` event, emitted when it appears your code is leaking memory.\n\n- A `stats` event, emitted occasionally, giving you\n  data describing your heap usage and trends over time.\n\n- A `HeapDiff` class that lets you compare the state of your heap between\n  two points in time, telling you what has been allocated, and what\n  has been released.\n\n\nInstallation\n------------\n\n- `npm install memwatch`\n\nor\n\n- `git clone git://github.com/lloyd/node-memwatch.git`\n\n\nDescription\n-----------\n\nThere are a growing number of tools for debugging and profiling memory\nusage in Node.JS applications, but there is still a need for a\nplatform-independent native module that requires no special\ninstrumentation.  This module attempts to satisfy that need.\n\nTo get started, import `node-memwatch` like so:\n\n```javascript\nvar memwatch = require('memwatch');\n```\n\n### Leak Detection\n\nYou can then subscribe to `leak` events.  A `leak` event will be\nemitted when your heap usage has increased for five consecutive\ngarbage collections:\n\n```javascript\nmemwatch.on('leak', function(info) { ... });\n```\n\nThe `info` object will look something like:\n\n```javascript\n{ start: Fri, 29 Jun 2012 14:12:13 GMT,\n  end: Fri, 29 Jun 2012 14:12:33 GMT,\n  growth: 67984,\n  reason: 'heap growth over 5 consecutive GCs (20s) - 11.67 mb/hr' }\n```\n\n\n### Heap Usage\n\nThe best way to evaluate your memory footprint is to look at heap\nusage right aver V8 performs garbage collection.  `memwatch` does\nexactly this - it checks heap usage only after GC to give you a stable\nbaseline of your actual memory usage.\n\nWhen V8 performs a garbage collection (technically, we're talking\nabout a full GC with heap compaction), `memwatch` will emit a `stats`\nevent.\n\n```javascript\nmemwatch.on('stats', function(stats) { ... });\n```\n\nThe `stats` data will look something like this:\n\n```javascript\n{\n  \"num_full_gc\": 17,\n  \"num_inc_gc\": 8,\n  \"heap_compactions\": 8,\n  \"estimated_base\": 2592568,\n  \"current_base\": 2592568,\n  \"min\": 2499912,\n  \"max\": 2592568,\n  \"usage_trend\": 0\n}\n```\n\n`estimated_base` and `usage_trend` are tracked over time.  If usage\ntrend is consistently positive, it indicates that your base heap size\nis continuously growing and you might have a leak.\n\nV8 has its own idea of when it's best to perform a GC, and under a\nheavy load, it may defer this action for some time.  To aid in\nspeedier debugging, `memwatch` provides a `gc()` method to force V8 to\ndo a full GC and heap compaction.\n\n\n### Heap Diffing\n\nSo far we have seen how `memwatch` can aid in leak detection.  For\nleak isolation, it provides a `HeapDiff` class that takes two snapshots\nand computes a diff between them.  For example:\n\n```javascript\n// Take first snapshot\nvar hd = new memwatch.HeapDiff();\n\n// do some things ...\n\n// Take the second snapshot and compute the diff\nvar diff = hd.end();\n```\n\nThe contents of `diff` will look something like:\n\n```javascript\n{\n  \"before\": { \"nodes\": 11625, \"size_bytes\": 1869904, \"size\": \"1.78 mb\" },\n  \"after\":  { \"nodes\": 21435, \"size_bytes\": 2119136, \"size\": \"2.02 mb\" },\n  \"change\": { \"size_bytes\": 249232, \"size\": \"243.39 kb\", \"freed_nodes\": 197,\n    \"allocated_nodes\": 10007,\n    \"details\": [\n      { \"what\": \"String\",\n        \"size_bytes\": -2120,  \"size\": \"-2.07 kb\",  \"+\": 3,    \"-\": 62\n      },\n      { \"what\": \"Array\",\n        \"size_bytes\": 66687,  \"size\": \"65.13 kb\",  \"+\": 4,    \"-\": 78\n      },\n      { \"what\": \"LeakingClass\",\n        \"size_bytes\": 239952, \"size\": \"234.33 kb\", \"+\": 9998, \"-\": 0\n      }\n    ]\n  }\n```\n\nThe diff shows that during the sample period, the total number of\nallocated `String` and `Array` classes decreased, but `Leaking Class`\ngrew by 9998 allocations.  Hmmm.\n\nYou can use `HeapDiff` in your `on('stats')` callback; even though it\ntakes a memory snapshot, which triggers a V8 GC, it will not trigger\nthe `stats` event itself.  Because that would be silly.\n\n\nFuture Work\n-----------\n\nPlease see the Issues to share suggestions and contribute!\n\n\nLicense\n-------\n\nhttp://wtfpl.org\n","readmeFilename":"README.md","users":{"mastayoda":true,"markthethomas":true}}