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, ...
Get Building Scalable Apps with Redis and Node.js now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.