Skip to content

bug(mat-dialog): Memory leak after close mat-dialog #31044

@christophedurupt-yooz

Description

@christophedurupt-yooz

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

When open and then close a mat-dialog, the elements linked to the mat-dialog and its contents remain in the DOM in memory in "Detached elements" state.
Each time a mat-dialog is opened/closed the phenomenon repeats itself, and the number of "detached elements" only increases.

Reproduction

Steps to reproduce:

  1. Create new angular project
  2. Create dialog component (like this: https://material.angular.io/components/dialog/overview)
  3. put a element in the dialog-component.html
  4. compile
  5. open chrome dev tools -> memory
  6. take a first snapshot with memory dev tools
  7. open and close the dialog multiple times, use the garbage collector afterwards
  8. take a second snapshot with memory dev tools
  9. compare the two snapshots
  10. look at "detached"
    => several count (for each open/close mat-dialog) of "Detached <mat-dialog-container" (and all children) stay in the DOM

Expected Behavior

After mat-dialog closed, we expect not to see "Detached " in memory (to prevent from memory leak)

Actual Behavior

Image

Environment

  • Angular:
  • CDK/Material:
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2The issue is important to a large percentage of users, with a workaroundarea: material/dialog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions