Skip to content

Instantly share code, notes, and snippets.

@gergelyke
Created December 11, 2015 07:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergelyke/21c5ded2593eda8b8291 to your computer and use it in GitHub Desktop.
Save gergelyke/21c5ded2593eda8b8291 to your computer and use it in GitHub Desktop.
const heapdump = require('heapdump')
const app = require('koa')()
const router = require('koa-router')()
const log = [];
router.get('/', function *(next) {
log.push(this.headers)
this.body = {
status: 'finding a leak'
}
})
app
.use(router.routes())
.use(router.allowedMethods())
app.listen(process.env.PORT || 3000)
@saxena-gaurav
Copy link

could you explain how declaring log as global variable causing memory leak?

@steevhise
Copy link

could you explain how declaring log as global variable causing memory leak?

log being global means it never goes out of scope, never gets garbage collected. but with each http request it's growing in size. hence, memory leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment