Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Express.js on Node.js have a memory leak?

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 the graphic from new relic

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.

Memory keeps growing

like image 789
user3211198 Avatar asked Feb 19 '15 10:02

user3211198


1 Answers

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.

enter image description here

like image 119
Sax Avatar answered Nov 16 '22 18:11

Sax