When opening and then closing a mat-dialog, the elements linked to the mat-dialog and its contents remain in the DOM as detached elements in memory.
Each time a mat-dialog is opened/closed, the issue repeats, and the number of detached elements only increases (never released).
Reproduction Steps:
- Create a new Angular project
- Create a dialog component (example: Angular Material Dialog).
- Add an element inside
dialog-component.html. - Compile the project.
- Open Chrome Dev Tools → Memory tab.
- Take a first snapshot using the memory tool.
- Open and close the dialog multiple times, then trigger garbage collection.
- Take a second snapshot with the memory tool.
- Compare the two snapshots.
- Check the "Detached" section.
Observed Behavior:
Multiple instances of detached <mat-dialog-container> (and all children) persist in memory per open/close cycle.

After closing mat-dialog, there should be no detached elements remaining in memory (to prevent memory leaks).
