title: node.js RSS memory grows over time despite fairly consistent heap sizes
body: <p>I've got a node.js application where the RSS memory usage seems to keep growing despite the heapUsed/heapTotal staying relatively constant.</p>
  
  <p>Here's a graph of the three memory measurements taken over a week (from <code>process.memoryUsage()</code>):</p>
  
  <p><img src="https://i.stack.imgur.com/pBJ0m.png" alt="memory graph"></p>
  
  <p>You may note that there's a somewhat cyclical pattern - this corresponds with the application's activity throughout each day.</p>
  
  <p>There actually does seem to be a slight growth in the heap, although it's nowhere near that of the RSS growth.  So I've been taking heap dumps every now and then (using node-heapdump), and using Chrome's heap compare feature to find leaks.<br>
  One such comparison might look like the following (sorted by size delta in descending order):</p>
  
  <p><img src="https://i.stack.imgur.com/rG0oc.png" alt="heap dump"></p>
  
  <p>What actually shows up does depend on when the snapshot was taken (eg sometimes more Buffer objects are allocated etc) - here I've tried to take a sample which demonstrates the issue best.</p>
  
  <p>First thing to note is that the sizes on the left side (203MB vs 345MB) are much higher than heap sizes shown in the graph.  Secondly, the size deltas clearly don't match up with the 142MB difference.  In fact, sorting by size delta in ascending order, many objects have be <em>deallocated</em>, which means that the heap should be smaller!</p>
  
  <p>Does anyone have any idea on:</p>
  
  <ul>
  <li>why is this the case? (RSS constantly growing with stable heap size)</li>
  <li>how can I stop this from happening, short of restarting the server every now and then?</li>
  </ul>
  
  <p>Other details:<br>
  Node version: 0.10.28<br>
  OS: Ubuntu 12.04, 64-bit</p>
  
  <p>Update: list of modules being used:</p>
  
  <ul>
  <li><a href="https://github.com/caolan/async" rel="noreferrer">async</a> v0.2.6</li>
  <li><a href="https://www.npmjs.org/package/log4js" rel="noreferrer">log4js</a> v0.6.2</li>
  <li><a href="https://github.com/felixge/node-mysql" rel="noreferrer">mysql</a> v2.0.0-alpha7</li>
  <li><a href="http://www.nodemailer.com/" rel="noreferrer">nodemailer</a> v0.4.4</li>
  <li><a href="https://github.com/TooTallNate/node-time" rel="noreferrer">node-time</a> v0.9.2 (for timezone info, not to be confused with nodetime)</li>
  <li><a href="https://github.com/sockjs/sockjs-node" rel="noreferrer">sockjs</a> v0.3.8</li>
  <li><a href="http://underscorejs.org/" rel="noreferrer">underscore</a> v1.4.4</li>
  <li><a href="https://github.com/arunoda/node-usage" rel="noreferrer">usage</a> v0.3.9 (for CPU stats, not used for memory usage)</li>
  <li><a href="https://www.npmjs.org/package/webkit-devtools-agent" rel="noreferrer">webkit-devtools-agent</a> v0.2.3 (loaded but not activated)<br>
  <a href="https://github.com/bnoordhuis/node-heapdump" rel="noreferrer">heapdump</a> v0.2.0 is loaded when a dump is made.</li>
  </ul>
  
  <p>Thanks for reading.</p>