Skip to content

mat-select memory leak, DOM nodes count increase #14419

@c214153

Description

@c214153

What is the expected behavior?

Including a mat-select component and opening it in a dialog should not cause memory leaks/DOM nodes increase.

What is the current behavior?

In Angular Material 2 and 5, if mat-select was opened in a dialog (not necessary to select anything), closing the dialog will increase DOM nodes count.
In versions 6 and 7, the DOM nodes count will increase even it the mat-select was not opened.

What are the steps to reproduce?

Versions:
4 - https://angular-material-2-select-leak.stackblitz.io
5 - https://angular-material-5-select-leak.stackblitz.io
6 - https://angular-material-6-select-leak.stackblitz.io
7 - https://angular-material-7-select-leak.stackblitz.io
(the resulting window links, stackblitz edit links below)

  1. Open the dialog by pressing the button. Open the select menu. Close the dialog.
    (versions 6 & 7 do not required the select being opened, will still leak)
  2. Repeat 1) a couple of times to avoid lazy loading effects.
  3. Run garbage collector (F12, Memory tab, garbage can icon)
  4. Memorize DOM nodes count (F12, Performance monitor)
  5. Do 1), then garbage collect.
  6. The DOM nodes count will increase in every such action.

Stackblitz editable links:
2 - https://stackblitz.com/edit/angular-material-2-select-leak
5 - https://stackblitz.com/edit/angular-material-5-select-leak
6 - https://stackblitz.com/edit/angular-material-6-select-leak
7 - https://stackblitz.com/edit/angular-material-7-select-leak

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 4, 5, 6, 7; Angular Material 2, 5, 6, 7
Windows 10, Chrome 70, Typescript 3

Is there anything else we should know?

Similar functionality can be achieved with mat-menu component. It does not produce memory leaks in all versions.
A workaround is possible with autocomplete as well,, however in version 6 & 7 it also leaks.

Metadata

Metadata

Assignees

Labels

GThis is is related to a Google internal issueP2The issue is important to a large percentage of users, with a workaround

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions