New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dialog causes a memory leak when Dialog component contains mat-form-field #15823
Comments
This is caused by @angular/animations package failing to clean up cached elements. The issue occurs when both a parent component (in this case dialog-container) and a child component (mat-form-field-hint-wrapper) has a set of animation triggers. A couple of issues tracking leaks are potentially related: angular/angular#30728 Contrary to other error cases, every time Dialog component is opened, a new set of elements is cached and subsequently leaked. This is due to a new namespaceId being created each time a dialog is opened. Thus the leaks build up rather than taper off in this case. The layout is roughly like so:
An issue should probably be raised for @angular/animations package |
@rhartvig The memory leak still persists even after removing the animations module |
@njofce , I guess you're using NoopAnimationsModule instead of BrowserAnimationsModule? If so, I guess that doesn't change the offending code paths. IIRC the issue is in |
@rhartvig Yes, you are right. |
Hi, does anyone have a workaround for this? We have a lot of forms inside dialogs in our app and seeing a huge build up of unreleased nodes. |
@jpduckwo Try to use ngModel instead of FormGroups/FormControl |
@jpduckwo , I can offer a workaround that address the leaks I am seeing: https://stackblitz.com/edit/angular-yx1kuw-fgdzjg Notice in dialog component constructor:
and surrounding dialog content:
Ie. a manual destroy of dialog content before dialog is closed. To see how this makes a difference:
|
Thanks so much guys, that's a great idea I'll give it a test in our app. I'm thinking of having a stab at creating a pull request to fix this issue, bit crazy when you think about it really... |
I believe this could be the root cause issue: angular/angular/issues/25744 |
Should've been fixed in 9.0.0-rc.7 by angular/angular@835ed0f. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
What is the expected behavior?
Instantiating a dialog with a component that contains
mat-form-field
element causes a DOM node memory leak.What is the current behavior?
Memory leak
What are the steps to reproduce?
https://stackblitz.com/edit/angular-yx1kuw?file=app%2Fdialog-overview-example-dialog.html
Try to open and close the dialog several times. Notice each time the number of detached DOM nodes gets higher and forcing garbage collection doesn't reduce it.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular Material: 7.3.7
Chrome: 73.0.3683.103
Is there anything else we should know?
Could be related to #10188
The text was updated successfully, but these errors were encountered: