react: Bug: Memory leak in react while focusing input elements
I 've noticed that having an input element focused and unmounting its owner component doesn’t actually free up this component from the js heap , I 've created this simple blnkr to demonstarate this which add a dummy X to a ref inside a component that has an input element
React version: 17.0.2
Steps To Reproduce
- Go to this plnkr
- Click Tab Two
- Click the
Grow buttona few times - Take a heap snapshot
- Click the Grow button a few more times
- IMPORTANT Focus the input element by clicking into it
- Click Tab One ( This unmount the component that own the ref to the list )
- Take another heap snapshot ( after running the GC)
- Compare between the two snapshots
- The added string
Xwill be found within the `concat check the screenshot
Link to code example: can be found above
The current behavior
The current component that own the input element is still being there in the memory and doesn’t free up its own resources afer being unmounted.
The expected behavior
The current component shloud free up its resources whenever being unmounted
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 15 (1 by maintainers)
Commits related to this issue
- fix(app): chrome bug leck memory after click, should remove input on destroy component (https://github.com/facebook/react/issues/26069) — committed to albnavarro/mobbu by albnavarro a year ago
哈哈,都是Chinese,我们用中文交流吧,你去抖音搜索一下 “游离节点造成的内存泄露”。就明白解决办法了
@YagamiNewLight I think This issue has already been resolved within react 18 , however I 'm not sure if there’s a workaround for this in previous versions