Created
December 11, 2015 07:28
-
-
Save gergelyke/21c5ded2593eda8b8291 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
could you explain how declaring log as global variable causing memory leak?