O'Reilly logo

Building Scalable Apps with Redis and Node.js by Joshua Johanan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Taking heap snapshots

In JavaScript, a heap snapshot will have all the objects that are not going to be garbage collected. This is perfect for tracking down memory leaks. We had briefly touched on memory leaks in Chapter 6, Using Bower to Manage Our Frontend Dependencies. Here, we will create some memory leaks on both the backend and frontend to see what they look like.

First, we will create a memory leak in Node.js. Create a new file named leak.js and put the following code into it:

var agent = require('webkit-devtools-agent'); var express = require('express'); var app = express(); var http = require('http'); var server = http.createServer(app); server.setMaxListeners(1000000); app.use(express.static(__dirname + '/static')); app.get('/', function(req, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required