-
Notifications
You must be signed in to change notification settings - Fork 46k
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: Detached DOM nodes exist when component is unmounted #23214
Comments
Is there anyone taking a look or what else do I need to provide for further investigation? |
Hello @snakepoongmail, is this causing you any troubles? I think this is a side effect of how React Fiber holds onto pieces of data and is harmless. The data will eventually be cleaned up. |
Hello @sammy-SC , thx for your responding. The issue now is I'm not quite sure about the timing when this data will be clean up. During the test, I've tried waiting for about 5 mins, clicking GC button in devTool, but it won't help freeing those occupied memory. Those Detached DOM elements should be considered as memory leak, in my application there are other detached DOM elements found held by React Fiber as well which means they are not able to be collected by GC, the size of the leak could be incrementing over time may end up crashing the application by consuming too many memory. Especially for building big and long running applications, memory leak is fatal for not being tackle well. |
@snakepoongmail in DEV tools you can see exactly what is retaining the object. In another issue it was DevTools. Please check what is retaining the object. |
It seems like we are experiencing this issue with React 17 in our app. The number of nodes just grows and never they never get clean up. I've tried switching to React 18 without success. Is there anything we can do? Are there any known workarounds or ways to investigate? |
Hello @sammy-SC! Thank you for getting back to me. Not sure what you mean by retain cycles, can you elaborate? By investigating deeper we discovered that the leak is caused by a Looking at the code we see nothing that could be causing it. Whatever needs to be clean up (like One specific thing about this code is that ref is used in multiple function wrapped into And by looking at the devtools I can see that
Also are these fixes going to be available for React 17? We are using it and it's unlikely we will be able to migrate soon. |
By retain cycles I meant things like missing
The fix is for problem specific to React 18, so that probably won't be the issue you're running into. |
+1 |
This seems to be a related issue to the one I posted recently: #25772 |
is there solution for this bug? :'( |
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! |
bump |
I've written a simple React APP which contains 2 buttons, one is to increase the count number trigger the child component to create a table element with some random numbers, another is to toggle mount/unmount status of the child component.
I found that just a simply mount the component then unmount it which leaves detached DOM nodes in memory profiling.
Following below steps:
but if I mount and unmount the component again by adding 3, 4 steps below:
In such orders, those detached DOM nodes will be cleaned. Is there any reason why those detached DOM nodes are not clear for the first time but distinguished by the second time the component is unmounted?
![image](https://user-images.githubusercontent.com/89285155/151799932-1f63b8a8-ab7c-41cf-b703-358787e2870e.png)
React version: 17.0.2
Steps To Reproduce
Link to code example:
https://v6dhm.csb.app/
code attached:
The current behavior
Detached HTMLTable* are found in the devTool memory timeline
The expected behavior
No Detached DOMs are found in the devTool memory timeline
The text was updated successfully, but these errors were encountered: