2

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:

  1. Create a new Angular project
  2. Create a dialog component (example: Angular Material Dialog).
  3. Add an element inside dialog-component.html.
  4. Compile the project.
  5. Open Chrome Dev Tools → Memory tab.
  6. Take a first snapshot using the memory tool.
  7. Open and close the dialog multiple times, then trigger garbage collection.
  8. Take a second snapshot with the memory tool.
  9. Compare the two snapshots.
  10. Check the "Detached" section.

Observed Behavior:

Multiple instances of detached <mat-dialog-container> (and all children) persist in memory per open/close cycle.

image of debugger showing detached elements

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

1 Answer 1

2

I had started to notice the same thing, though I don't know if it is new or not. You can even see it occur on the angular material site, so it isn't an implementation issue. Open that first dialog without animation button a few times. If you click outside to close, the overlay is leaked, not the dialog component it self, but if you click anywhere inside the dialog at all, that becomes a leak.

https://material.angular.dev/components/dialog/examples

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.