-
Notifications
You must be signed in to change notification settings - Fork 791
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
fix(runtime): clear up rootAppliedStyles #6087
Conversation
I've done some further testing on the following reproduction case: https://github.com/alicewriteswrongs/stencil-1079-memory-leak-example Behavior before patch: Behavior after patch: and hostrefs remain the same at all times: |
Investigated another reproduction case: https://github.com/joewoodhouse/stencil-modal-memory-investigation I made the same observations: the performance monitor and DOM node curve looked the same for the version with as well as without patch, however without the patch the number of nodes in the hostref WeakMap would continue to increase: while in the patched version, it would remain around 32 nodes. |
fb8335e
to
22a6ade
Compare
Further investigations have shown that cleaning up the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work and analysis @christian-bromann 🚀
25ceebe
to
e1053d2
Compare
Hey @christian-bromann! Great work, and many thanks to you for that. Do you have a new version with the last changes that I can use for testing? |
@seregindev I just published a new dev version |
🙈 thanks, great catch! Pushed a new dev build |
Updated: |
…tate updates have been processed
Last update: |
What is the current behavior?
There seems to be a memory leak within Stencil that causes performance problems as documented in:
It turns out that Stencil doesn't properly clear up its
hostRefs
global when elements are removed from the DOM. Given that thehostRefs
global is never garbage collected, all its value will remain in memory which requires us to do some manual cleanup. Furthermore, we have been using references in another global variable calledrootAppliedStyles
which also never gets cleaned up.What is the new behavior?
This patch enhances the
disconnectedCallback
hook to clean up detached nodes from thehostRefs
androotAppliedStyles
maps.Documentation
Does this introduce a breaking change?
Testing
I am investigating if we can add some memory checks through Puppeteer and Chrome Devtools.
Other information
A development release is now available at
@stencil/[email protected]
. If anyone is able to help validate the memory leak fix, your assistance would be greatly appreciated.