Skip to content

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

@ling1726

Description

@ling1726
Contributor

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.

Activity

theKashey

theKashey commented on Oct 9, 2023

@theKashey
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.

github-actions

github-actions commented on Apr 10, 2024

@github-actions

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 commented on Apr 17, 2024

@github-actions

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @theKashey@ling1726

        Issue actions

          Remove alternate tree DOM element retainers to help with memory leak investigations · Issue #25391 · facebook/react