Subscribe on changes!

Memory leak when using reactive/ref in SSR mode

avatar
Mar 30th 2022

Version

3.2.31

Reproduction link

github.com/yeyan1996/vite-ssr

Steps to reproduce

  1. download repository
  2. using npm run serve to start the server
  3. see reactiveMap in the dist/server/entry-server folderimage image

What is expected?

reactiveMap should be empty in server SSR

What is actually happening?

reactiveMap is expanding


This issue is similar to #5208

I didn't find any other variable to tell if it's currently server-rendered(maybe window === undefined?)

So is it possible to build a branch for SSR? (I see there is a __SSR__ variable in the source code)

Or other solutions, thx

avatar
Apr 14th 2022

We'll need a bit more info to confirm that this is indeed a memory leak - reactiveMap is a WeakMap - which means an entry can be released if its key is no longer referenced anywhere.

Your console.log() may cause the console to iterate the WeakMap and thus prevent all keys to be released.

To show a memory leak, please provide a repro similar to that of #5208.