Palindrom / JSONPatcherProxy

ES6 proxy powered JSON Object observer that emits JSON patches when changes occur to your object tree.
94 stars 14 forks source link

Memory leak #77

Open pablo-mendoza opened 3 months ago

pablo-mendoza commented 3 months ago
async function test()
{
    const JSONPatcherProxy  = (await import("jsonpatcherproxy")).JSONPatcherProxy

   let gS = {
        uno: {
        },
   }

   let jsonPatcherProxy  = new JSONPatcherProxy(gS)

    let objc = jsonPatcherProxy.observe(true);

  setInterval(() => {
                let generate = jsonPatcherProxy.generate()

                console.log("Generate", generate.length)

        },500)

  setInterval(() => {
                for (let i = 0; i < 1000; i++)
                objc.uno = { test: "test" }
        },1)

}

test()

This library has a huge memory leak. Just run the above program and see memory usage increase until node is killed.

nomeaning777 commented 3 months ago

I remember there was a memory leak in the part using Map. It can be resolved by using WeakMap, like in this commit: https://github.com/argentumcode/JSONPatcherProxy/commit/43f7b2bc84a75b955fd323e259531f8e4128ff29

If the maintainer is okay with it, I can create a PR.