-
Notifications
You must be signed in to change notification settings - Fork 10.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
fix(gatsby-link) Clean up IntersectionObservers to fix a memory leak #17056
fix(gatsby-link) Clean up IntersectionObservers to fix a memory leak #17056
Conversation
…t to prevent memory leaks Associated issue: #12198
Nice! Thanks! Does this need done in gatsby-image as well? |
Don’t know yet, will have a look tomorrow! |
I did a bit of testing and could not reproduce the memory leak for gatsby/packages/gatsby-image/src/index.js Lines 322 to 326 in 49ea6dc
|
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.
This is great! 🎉 I feel like intersection observer should only be created once but that's not really a concern for this PR.
I added a small nit about adding a guard for this.io
to make sure it exists.
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.
Works like a charm! ❤️ thanks for fixing our bad code 😂
…#17056) * fix(gatsby-link) Clean up IntersectionObserver on componentWillUnmount to prevent memory leaks Associated issue: gatsbyjs#12198 * Check whether IntersectionObserver exists before unobserving
Thank you once again for this! Featuring it on this month's Gazette in #17548 |
Description
This PR fixes a memory leak caused by
IntersectionObserver
s not being cleaned up in case the intersection is never reached.Many thanks to @atomiks who did a thorough investigation on the matter and came up with this solution 👏
I tested it on https://reactjs.org with the following procedure:
Intersection
in the memory heap snapshot and seeingDetached…
entries.Here’s a comparison of before and after the fix (tested locally):
Related Issues
Fixes #12198.