JSONPatcherProxy icon indicating copy to clipboard operation
JSONPatcherProxy copied to clipboard

Memory leak

Open pablo-mendoza opened this issue 1 year ago • 1 comments

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.

pablo-mendoza avatar Jul 27 '24 20:07 pablo-mendoza

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.

nomeaning777 avatar Jul 28 '24 00:07 nomeaning777