what should I do to fix the node map memory leak

90 views Asked by At

I am using y-websocket 1.5.0 as the server side to do some collaboarate task. Now I found the y-websocket always restart after running for some peroid of time. I tried to dump the memory and found the map with 0 element contains 50000+. It seems the map did not released properly after use.

  • When did the map will cause memory leak in node?
  • how to properly close the map after use?

I have tried to fix the memory leak map in y-websocket https://github.com/yjs/y-websocket/blob/master/bin/utils.js#L66 like this:

if (doc.conns.size === 0 && persistence !== null) {
      // if persisted, we store state and destroy ydocument
      persistence.writeState(doc.name, doc).then(() => {
        doc.destroy()
      })
      docs.delete(doc.name)
      doc.conns = null
    }

it seems break the workflow of y-websocket. what should I do to fixed this problem? there is some issue about this: https://github.com/yjs/y-websocket/issues/145 and https://github.com/yjs/y-websocket/issues/163

1

There are 1 answers

1
Caleb Pathi On
  1. Refactoring Your Code In many cases, refactoring your code to avoid common causes of memory leaks (such as global variables and event listeners) can help fix the issue. ...
  2. Using a Garbage Collector Node.js has a built-in garbage collector that can help clean up unused memory. ...
  3. Monitoring Your Application