Skip to content
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

Remove alternate tree DOM element retainers to help with memory leak investigations #25391

Closed
ling1726 opened this issue Oct 4, 2022 · 3 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@ling1726
Copy link
Contributor

ling1726 commented Oct 4, 2022

Hi,

#16087, #15157 (and other issues) point out that React keeps an alternate tree that can retain DOM elements in fibers such as the stateNode property. This can make it hard to debug memory leaks in larger sites/applications since they are a false positive.

To make the investigation process easier, would it be possible to recommend/suggest a way to somehow clean up the retainers in alternate fiber so that there is less noise?

We have some tools that do this to more or less successfully by pasring the fiber tree and setting alternate.stateNode to null.

I understand that fibers are internal API and that anything retained in alternate tree should fix itself eventually if the userland code is not leaky. However when there are leaks in userland the alternate tree can make root causing real memory leaks quite hard, even for those who are aware that retention in alternate trees is expected and a normal behaviour of React.

@theKashey
Copy link
Contributor

Indeed this is a huge problem - there are many different possibilities to leak reference to a FiberNode and having a small and single reference to no longer used fiber you might have reference to a big chunk of VDOM existed at that moment.

React cleans some fibers(https://github.com/facebook/react/pull/17666/files), but the majority left up to GC to handle. While for many cases doing GC's work manually will be just a waste of CPU time, there are many other cases when it will really aid problem or at least ease discovery or the root cause, the one currently being buried very deep down in a fiber's cyclic structure.

Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

2 participants