-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Memory leak when discarding used editors #5654
Comments
Would this tell you where the memory is still being referenced from? It is detached from the DOM so I'm not terribly concerned to be honest |
For our application, we are seeing memory balloon over time. As soon as we stopped the editor from being re-created, memory stabilized. We have many more extensions that take up a decent amount of memory, so the editor not going away leads to huge memory consumption over time. Our application is not reloaded for weeks at a time. |
It should be noted that detached DOM nodes in a memory snapshot are ones that are referenced and cannot be cleaned up by the garbage collector. GC is forced before each snapshot. |
Alright, well then this will need some research into what is actually keeping these references around. Unfortunately, a pretty broad surface area to look into. I would be willing to take a patch that resolves this |
The problem is here: tiptap/packages/core/src/Editor.ts Lines 371 to 376 in f76515a
There is a circular reference between the editor and the DOM node. How this gets exercised actually has nothing to do with editing. Rather, it is something along these lines:
The problem isn't just with It looks like the ref is only there for testing, which means you should only run that code during testing. If you truly need a reference, it should be done via a data attribute to look things up. Something along the lines of: // Expose this to testing env
Editor.aliveEditors = new Map<string, Editor>()
// in Editor constructor:
this.id = nextEditorId++
Editor.aliveEditors.set(this.id, this)
// in Editor destroy:
Editor.aliveEditors.delete(this.id) |
What if we remove this reference on destroy? |
Tested and that works. |
I posted a CR that only runs the code in Cypress. I can't get tests to run, so you'll need to verify that they work. The alternative is to deref on destroy, but if any errors occur that prevent a clean destroy, the leak would persist. As the code is test-only, it is best if it just runs there. |
I do prefer just de-referencing it in the The PR you made was into your own repo, but I'll make one into here |
I released this with v2.7.4 |
Affected Packages
pm, react, starter-kit, extension-color, extension-list-item, extension-list-style
Version(s)
2.7.2
Bug Description
I have observed Editor memory leaks when the editor instance is re-created. I create a repro that simply uses the demo app.
Browser Used
Chrome
Code Example URL
https://github.com/schontz/tiptap-react-leak
Expected Behavior
There should only be a single editor in memory, while instead there are many.
Additional Context (Optional)
Dependency Updates
The text was updated successfully, but these errors were encountered: