nuxt-community / koa-template

Starter template for Nuxt.js with KoaJS.
https://koa.nuxtjs.org
382 stars 62 forks source link

server/index.js - there is circular reference - it's potential memory leak #67

Closed Perlover closed 4 years ago

Perlover commented 4 years ago

Hello!

I generated koa template for nuxt and i see there:

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
  })

But i think there is circular reference and this is a potential memory leak

I would did by this way:

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
    ctx.req.ctx = null
  })
This question is available on Nuxt community (#c48)
ghost commented 4 years ago

This issue as been imported as question since it does not respect koa-template issue template. Only bug reports and feature requests stays open to reduce maintainers workload. If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically. Your question is available at https://cmty.app/nuxt/koa-template/issues/c48.

Perlover commented 4 years ago

Due to graph GC a circular references not problem for node

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management#Mark-and-sweep_algorithm

So my patch is not patch