Skip to content

Instantly share code, notes, and snippets.

@abhinavdhasmana
Created January 3, 2017 04:02
Show Gist options
  • Save abhinavdhasmana/135067a3706f9dd59f6b9720ff0b00ba to your computer and use it in GitHub Desktop.
Save abhinavdhasmana/135067a3706f9dd59f6b9720ff0b00ba to your computer and use it in GitHub Desktop.
Example of memory leak in node.js using singleton pattern
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 3000 });
const myBigFatArray = [];
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
let temp = [];
for (let i = 0; i < 10000; i++) {
temp.push(i);
}
myBigFatArray.push(temp);
reply('Hello, world!');
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log(`Server running at: ${server.info.uri}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment