Empty Node Module Memory Usage

2 min read Original article ↗

Unstoppable memory usage increase

Node is increasingly using RSS and Heap memory for doing nothing

My environment

  • CPU: 2.3 GHz Intel Core i7
  • OS: OSX Yosemite 10.10.1 (14B25)
  • RAM: 16 GB 1600 MHz DDR3
  • Node.JS verison: v0.11.14

How to reproduce problem

Just start an empty node module and log memory usage each seconds:

setInterval(function() {
    console.log(process.memoryUsage());
}, 1000);

For better readability, let's use this instead:

var unit = ['', 'K', 'M', 'G', 'T', 'P'];

function bytesToSize(input, precision)
{
    var index = Math.floor(Math.log(input) / Math.log(1024));
    if (unit >= unit.length) return input + ' B';
    return (input / Math.pow(1024, index)).toFixed(precision) + ' ' + unit[index] + 'B'
}

var usage;

console.log('==================================');
console.log('  Empty Node Module Memory Usage  ');
console.log('==================================');

setInterval(function() {
    usage = process.memoryUsage();
    console.log('RSS: ' + bytesToSize(usage.rss, 3), 'and Heap:', bytesToSize(usage.heapUsed, 3), 'of', bytesToSize(usage.heapTotal, 3), 'total');
}, 1000);

Expected result

Memory usage should be constant

Actual result

Heap and RSS memory are increasing

My results:

==================================
  Empty Node Module Memory Usage  
==================================
RSS: 13.746 MB and Heap: 3.583 MB of 6.191 MB total
RSS: 13.824 MB and Heap: 3.626 MB of 6.191 MB total
RSS: 13.828 MB and Heap: 3.634 MB of 6.191 MB total
RSS: 13.832 MB and Heap: 3.637 MB of 6.191 MB total
RSS: 13.836 MB and Heap: 3.641 MB of 6.191 MB total
RSS: 13.840 MB and Heap: 3.645 MB of 6.191 MB total
RSS: 13.848 MB and Heap: 3.649 MB of 6.191 MB total
RSS: 13.852 MB and Heap: 3.653 MB of 6.191 MB total
RSS: 13.855 MB and Heap: 3.657 MB of 6.191 MB total
RSS: 13.871 MB and Heap: 3.661 MB of 6.191 MB total
RSS: 13.875 MB and Heap: 3.665 MB of 6.191 MB total
RSS: 13.879 MB and Heap: 3.669 MB of 6.191 MB total
RSS: 13.883 MB and Heap: 3.673 MB of 6.191 MB total
...