Skip to content

Dropdown Item Event Listeners not removed when component unmounts #10648

@pllcoster

Description

@pllcoster

Check existing issues

Actual Behavior

While investigating a possible memory leak in our App, I noticed that among the retained items causing memory use to increase, I was finding detached calcite-dropdown-items inside dropdowns/list items and lists that were retaining objects associated with their event handlers:

image

Expected Behavior

I expect event listeners to be cleaned up when the component unmounts, to prevent possible memory leaks.

Reproduction Sample

https://codesandbox.io/p/devbox/calcite-dropdown-event-listener-memory-leak-hvqggj

Reproduction Steps

From the sandbox, open the demo in a new tab or follow this link: https://hvqggj-5173.csb.app/

Open chrome dev tools and go to the memory tab then repeat the following operations:

  1. Click the large blue button that triggers the calcite dropdown to open
  2. Click the 'unmount button' button, that unmounts the calcite button and dropdown
  3. Click the 'mount button' button to remount the calcite button and its dropdown
  4. Take a memory snapshot in the browser dev tools

On each iteration the memory usage will increase by about 100MB, in the retained objects the number of BigObjects will increase, and the leaked objects will be retained by detached calcite-dropdown-item event handlers:

image

Reproduction Version

2.13.2

Relevant Info

Tested on Chrome Using React Calcite Components.

Regression?

No response

Priority impact

impact - p2 - want for an upcoming milestone

Impact

Event handlers not being cleaned up will result in memory leaks, which can cause problems if the event handlers have closure over large objects.

Calcite package

  • @esri/calcite-components
  • @esri/calcite-components-angular
  • @esri/calcite-components-react
  • @esri/calcite-design-tokens
  • @esri/eslint-plugin-calcite-components

Esri team

ArcGIS Knowledge

Metadata

Metadata

Labels

4 - verifiedIssues that have been tested, confirmed as mitigated, and are ready to close.ArcGIS KnowledgeIssues logged by ArcGIS Knowledge team members.bugBug reports for broken functionality. Issues should include a reproduction of the bug.calcite-componentsIssues specific to the @esri/calcite-components package.calcite-components-reactIssues specific to the @esri/calcite-components-react package.impact - p2 - want for an upcoming milestoneUser set priority impact status of p2 - want for an upcoming milestonep - mediumIssue is non core or affecting less that 60% of people using the library

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions