Skip to content

Memory Leak in mat-select Component #29697

@Emil-Blomquist

Description

@Emil-Blomquist

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I have identified a potential memory leak related to the mat-select component in Angular Material. Each time I interact with the mat-select component and navigate to a different page, the number of detached elements increases.

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-qufh72?file=src%2Fcomponents%2Fa%2Fa.component.css

Steps to Reproduce:

  1. Start at Component B.
  2. Navigate to Component A.
  3. Interact Component A's mat-select (simply open it and then have it closed)
  4. Navigate back to Component B.

Observed Behavior:

  • Each time the above steps are repeated, a pair of detached elements (the host element of Component A and a cdk-overlay div) is created.
  • Repeating this process N times results in N pairs of detached elements.
  • Below is included a screen grab of Edge's Detached Element development tool below for the case N = 3

detached_elements_edge

Impact:

  • While the memory impact may be minimal, it complicates debugging in complex applications due to the accumulation of small leaks.

Expected Behavior

  • Navigating between components and interacting with the mat-select should not result in any detached elements.

Actual Behavior

  • Each time the above steps are repeated, a pair of detached elements (the host element of Component A and a cdk-overlay div) is created.
  • Repeating this process N times results in N pairs of detached elements.

Environment

Angular CLI: 18.2.3
Node: 20.16.0
Package Manager: npm 10.8.1
OS: linux x64

Angular: 18.2.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, router

Package Version

@angular-devkit/architect 0.1802.3
@angular-devkit/build-angular 18.2.3
@angular-devkit/core 18.2.3
@angular-devkit/schematics 18.2.3
@schematics/angular 18.2.3
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue needs to be triaged by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions