Skip to content

Bug: Memory leak in react while focusing input elements #26069

@Elwazer007

Description

@Elwazer007

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

  1. Go to this plnkr
  2. Click Tab Two
  3. Click the Grow button a few times
  4. Take a heap snapshot
  5. Click the Grow button a few more times
  6. IMPORTANT Focus the input element by clicking into it
  7. Click Tab One ( This unmount the component that own the ref to the list )
  8. Take another heap snapshot ( after running the GC)
  9. Compare between the two snapshots
  10. The added string X will be found within the `concat check the screenshot

Screenshot 2023-01-28 at 1 13 12 AM

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions