Skip to content

Memory leak in react-select #5635

@Sh1d0w

Description

@Sh1d0w

When using react-select, after the component is destroyed by e.g. not rendering it or more realistic example by page navigation, it leave a detached nodes that can not be garbage collected because they are not freed properly somewhere.

Link to reproduce: https://codesandbox.io/s/blissful-dream-l22yoq?file=/src/App.js
How to reproduce: https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/memory-problems/dom-leaks

Steps:

  1. Open https://l22yoq.csb.app/
  2. Open devtools -> Detached elements and click Get Detached Elements button. Observe there are no detached elements
  3. click on the select and choose randomly options
  4. click the hide button below the select to stop rendering it
  5. click Get Detached Elements button in the devtools
  6. click collect garbage button to force GC
  7. click Analyse button to analyse the current heap snapshot
  8. see there is item that is still referenced, check the last column where you have @SomeNumber value

Video:

Screen.Recording.2023-05-10.at.9.07.40.mov

Expected behaviour:

When react-select is no longer rendered it should not leave detached elements, as they pile up and cause a memory leak.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting-author-responseIssues or PRs waiting for more information from the authorissue/bug-unconfirmedIssues that describe a bug that hasn't been confirmed by a maintainer yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions