Book Image

Building Scalable Apps with Redis and Node.js

By : Joshua Johanan
Book Image

Building Scalable Apps with Redis and Node.js

By: Joshua Johanan

Overview of this book

Table of Contents (17 chapters)
Building Scalable Apps with Redis and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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, res){
  //no-op listener
  for(var k=0; k < 1000; k++){
    server.on('request', function(e){var t = express;});
  }
  res.set('Important-Header', 'test-value');
  res.send('hello world<script src="/debug.js"></script>');
}...