-
Notifications
You must be signed in to change notification settings - Fork 822
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
Dialog memory leak (detached Dialog.Content) #3202
Comments
This has a pretty big impact in our usage of radix-ui. We have slowly been migrating from MUI to Radix, and we've recently noticed severe performance degradation. We could easily reproduce this memory leak, and we use dialog workflows quite extensively, this is therefore an urgent issue for us. If anyone has a workaround we could patch or apply that'd be highly appreciated. We will look for one in the meantime. We may need to revert to alternative dialog solutions in the short term if this issue is not picked up. |
Hi, I have tried to set the Dailog with This is indeed a serious problem, as I got hundreds of MB of memory used when opening the Dialog ( |
This is how I use the current Dialog (for shadcn/ui): https://codesandbox.io/p/sandbox/radix-ui-primitives-issues-3202-jzd42z use It seems that this does not cause the memory leak by doing so. Any feedback would be greatly appreciated! As this is just quick workaround. |
I can't get the garbage collector to remove all of the dialog nodes in your example either @Lexachoc. It is easy to reproduce if I type something in one of the input fields before closing the dialog. |
@Kjetiljv Thank you for pointing out! I only looked at the First time using it. Not sure how badly is the memory leak of my example. Could you please enlighten me if my example's memory leak situation better?The input fields are already there. Would retyping do anything about the memory leak? This is from the original example: both are reopened multiple time. |
@Lexachoc, sorry I should have formulated myself better. Your example seems to produce fewer dom nodes when I open and close the dialogg without making a change to its content. But if I type something in one of the input fields it will continue to grow. I made a video that I hope will explain it better. ScreenShot-000274.mp4 |
FYI - this behavior is reproducable with Radix Popover as well, but not as consistently. |
Bug report
Current Behavior
Every time a Dialog gets opened and then closed, a Detached
<div>
element (theDialog.Content
) gets detached but is never garbage collected, as if a reference was kept, preventing it. This represents a memory leak because opening and closing the dialog 20 times means 20 DetachedDialog.Content
elements as long as their whole tree of children, which makes the memory usage grow.Expected behavior
No reference should be held with the
Dialog.Content
element upon closing to allow proper garbage collection.Reproducible example
<div>
elements with therole=dialog
attribute get leaked (this is actually the Dialog.Content element)Suggested solution
Find which reference might not get removed when the dialog gets closed. I tried to search in the sources but am not able to notice anything.
Your environment
The text was updated successfully, but these errors were encountered: