fix: memory leak in worker component
Fix memory leak in the worker component: ydoc instances were not properly released after applying updates and writing to storage.
Hi @catssay,
Does this fix your memory leak problem? I'm curious because according:
https://github.com/yjs/y-redis/blob/61a13e4bcac85373bba24375cdacfba05e77f697/src/api.js#L295 https://github.com/yjs/y-redis/blob/61a13e4bcac85373bba24375cdacfba05e77f697/src/api.js#L300
We still need to pass ydoc to updateCallback & persistDoc, and afterTransaction will be called right after the transaction:
https://docs.yjs.dev/api/y.doc#event-handler
Does that mean releasing yodc too early?
Hi @catssay,
Does this fix your memory leak problem? I'm curious because according:
https://github.com/yjs/y-redis/blob/61a13e4bcac85373bba24375cdacfba05e77f697/src/api.js#L295
https://github.com/yjs/y-redis/blob/61a13e4bcac85373bba24375cdacfba05e77f697/src/api.js#L300
We still need to pass
ydoctoupdateCallback&persistDoc, andafterTransactionwill be called right after the transaction:https://docs.yjs.dev/api/y.doc#event-handler
Does that mean releasing
yodctoo early?
Thank you for your question! Yes, this does address the memory leak issue. The memory leak happens because ydoc cannot be released after being consumed in each cycle. From my observation, the event handler does not seem to be used further after the release.
It might be worth considering moving the destroy operation to occur after the store operation. However, based on my understanding, ydoc should remain unchanged once all updates from Redis have been applied. If we were to move the destroy operation outside of getDoc, it would require any caller of getDoc to take responsibility for releasing ydoc after its use. So I put the destroy operation after applying updates.