I am attempting to use node-memwatch to track down memory leaks in my application. Currently I am creating a HeapDiff when the app starts and then doing a diff when mem-watch detects a leak. I have found a few items that look suspect but I don't understand how I should map what is being reported to my code. For example, the following item is reported in the diff:
{ what: 'String',
size_bytes: 4785072,
size: '4.56 mb',
'+': 32780,
'-': 563 },
Which seems like a prime suspect for a memory leak. How can I figure out which piece of my code is causing this leak? In the examples they give on their site, what is typically something obvious like MyLeakyClass and not a system type...
It seems that feature is yet to be implemented:
"In particular, we want node-memwatch to be able to provide some examples of a leaked object (e.g., names of variables, array indices, or closure code)."
https://hacks.mozilla.org/2012/11/tracking-down-memory-leaks-in-node-js-a-node-js-holiday-season/
LeakingClass example should have been given from this code: https://github.com/lloyd/node-memwatch/blob/master/examples/basic_heapdiff.js
What that means is that you have created 32780 strings, and garbage collected 563, since starting your HeapDiff. (the ones you collected may or may not be ones created in this window; they could have existed already when the diff started). The total amount of memory used by strings has grown by 4.56mb. That could all be in one string, or it could be perfectly evenly distributed among the 32k strings. You have no data on that.
Strings, of course, show up all over your code. So my advice is, don't look at those. Look for objects with more trackable (greppable, rarer, whatever) names that are growing, even if they appear to be growing less than your strings, and track those. In the process, you may find your big leaks.