I have been using express on node.js running on a heroku server for a simple project. When I started using new relic to monitor the memory I noticed a slow memory leak pattern. I removed all the code I developed and all other node modules and left only express itself and new relic modules. I still observe the memory leak. 
I was wondering if this is express.js memory leak. 

Here is all the code left:
require('newrelic');
var express = require('express'); 
var app = express();
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
    app.set('port', process.env.PORT || 3000);
}
app.get('/', function ( req, res ) {
    res.send('The server is up and running!');
});
app.listen(app.get('port'), function() {
    console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env'));
});
And package.json
{
  "name": "memleakdebug",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.11.2",
    "newrelic": "^1.16.2"
  }
}
UPDATE1: Now growing memory even passed heroku's limit 512MB for free tiers. Garbage collection doesn't seem to work.

As Lasse replied, there is a memory leak in New Relic.
https://discuss.newrelic.com/t/memory-leaking-only-with-node-js-agent-installed/14448
I experimented and removed
require('newrelic');
As you can see in the image below, since I removed the New Relic agent there is no more memory leak.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With