You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Sidenav] Memory leak when used inside router-outlet #8862
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/sidenavperfThis issue is related to performance
As you can see in this commit, there is still one line which seems ok to me, but that needs to be commented out to completely fix the leak in the sample...
I did some digging on this and found that if I set dir="ltr" on the mat-sidenav-container it doesn't leek anymore. I wasnt't able to figure out why though...
@npen yeah looks like it should work to me, maybe try subscribing in ngAfterContentInit instead of the constructor? or if dir="ltr" somehow makes it work perhaps add a startWith(null)? I'm just kinda guessing at things though 😆
I am not an expert in either javascript or Angular, but I currently have a similar problem to this.
I have component with mat-sidnav-container, mat-sidenav and mat-sidenav-content which is used within a child route. It is therefore being used with a router-outlet inside a parent router-outlet.
I am using version 7.2.2 of @angular/material, but after each display of this component, all the nodes inside the mat-sidenav-container are left hanging and are never free to be garbage collected.
On doing some further investigation, I think that the problem that I am seeing relates to bug angular/angular#18606. The mat-drawer code is including an animation trigger with HostBinding.
When the drawer is destroyed, the animation information is not released, leaving references in playersByElement/statesByElement in TransitionAnimationEngine. The result is that all of the nodes within the drawer are left as detached elements when the sidenav is removed.
Is there a way that I can manually free up this animation ?
This problem still exists, but is not caused directly by the sidenav component, but as a result of the HostBinding on the animation code. It looks like the bug at angular/angular#18606 is also marked as fixed, so I will open a new issue.
As @FionaTreveil mentioned in previous comment, this is actually a bug in the core Angular animations package, not limited to the Angular Material sidenav component. The stackblitz example included here is just an adaptation of the one I referenced in my comment in angular/angular#24197 to demonstrate the general work-around is effective with the sidenav component too.
Hello, we are also experiencing this issue. Our components cannot be properly cleaned up when we add to the template. There doesn't need to be any content in the sidenav. If we remove this tag, memory cleanup works fine. Are there any updates on this?
Thank you @jsim5446, four years later, this is still an issue in angular 18, and I can confirm that your hint of adding: animations: [trigger("noop", [])] to the parent component does indeed resolve the memory leak.
@ciaranj are you sure that the workaround completely solves the issue? For me, prior, there is a leak every time I navigate back and forth. That is, after N visits the leak has occurred N times. However, after adding animations: [trigger("noop", [])] there is only a single leak, independent of N.
Hmm, I don’t have that project to hand currently. However, I may have just assumed that that single ‘leak’ was just something lazily initialised by angular, so didn’t treat it as a leak as it wasn’t leading to any memory growth?
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/sidenavperfThis issue is related to performance
Activity
[-]Memory leak when sidenav is inside router-outlet[/-][+][Sidenav] Memory leak when used inside router-outlet[/+]npen commentedon Dec 20, 2017
If it can help I found a few problems in drawer.ts:
npen@fe21cd7
As you can see in this commit, there is still one line which seems ok to me, but that needs to be commented out to completely fix the leak in the sample...
Abrissirba commentedon Feb 9, 2018
I did some digging on this and found that if I set dir="ltr" on the mat-sidenav-container it doesn't leek anymore. I wasnt't able to figure out why though...
mmalerba commentedon Feb 9, 2018
@npen yeah looks like it should work to me, maybe try subscribing in
ngAfterContentInitinstead of the constructor? or ifdir="ltr"somehow makes it work perhaps add astartWith(null)? I'm just kinda guessing at things though 😆sheiidan commentedon Nov 27, 2018
PR #13378 should fix the leak issue described above.
FionaTreveil commentedon Jan 25, 2019
I am not an expert in either javascript or Angular, but I currently have a similar problem to this.
I have component with mat-sidnav-container, mat-sidenav and mat-sidenav-content which is used within a child route. It is therefore being used with a router-outlet inside a parent router-outlet.
I am using version 7.2.2 of @angular/material, but after each display of this component, all the nodes inside the mat-sidenav-container are left hanging and are never free to be garbage collected.
The same code frees up all the nodes if I use
Thank you for any help you can provide.
FionaTreveil commentedon Feb 7, 2019
On doing some further investigation, I think that the problem that I am seeing relates to bug angular/angular#18606. The mat-drawer code is including an animation trigger with HostBinding.
When the drawer is destroyed, the animation information is not released, leaving references in playersByElement/statesByElement in TransitionAnimationEngine. The result is that all of the nodes within the drawer are left as detached elements when the sidenav is removed.
Is there a way that I can manually free up this animation ?
mmalerba commentedon Feb 7, 2019
It looks like that issue has been fixed, if you're still able to reproduce it you may want to comment there or open a new issue on angular/angular
FionaTreveil commentedon Feb 18, 2019
This problem still exists, but is not caused directly by the sidenav component, but as a result of the HostBinding on the animation code. It looks like the bug at angular/angular#18606 is also marked as fixed, so I will open a new issue.
jsim5446 commentedon Jun 7, 2020
Here is a repro that demonstrates this issue is still not fixed in Angular 9, but also shows a work-around that can eliminate the memory leak:
https://stackblitz.com/edit/angular-ivy-u1fvgw
As @FionaTreveil mentioned in previous comment, this is actually a bug in the core Angular animations package, not limited to the Angular Material sidenav component. The stackblitz example included here is just an adaptation of the one I referenced in my comment in angular/angular#24197 to demonstrate the general work-around is effective with the sidenav component too.
kevinclerc commentedon Jul 27, 2022
any news on this? still leaking memory for sidenav
toxik commentedon Apr 18, 2023
This is still reproducible :(
blasco commentedon Jul 12, 2023
Hi, I'm also experiencing this issue. Any updates?
ChristianKlima commentedon Jan 12, 2024
Hello, we are also experiencing this issue. Our components cannot be properly cleaned up when we add to the template. There doesn't need to be any content in the sidenav. If we remove this tag, memory cleanup works fine. Are there any updates on this?
ciaranj commentedon Jul 3, 2024
Thank you @jsim5446, four years later, this is still an issue in angular 18, and I can confirm that your hint of adding:
animations: [trigger("noop", [])]to the parent component does indeed resolve the memory leak.Emil-Blomquist commentedon Sep 4, 2024
@ciaranj are you sure that the workaround completely solves the issue? For me, prior, there is a leak every time I navigate back and forth. That is, after N visits the leak has occurred N times. However, after adding
animations: [trigger("noop", [])]there is only a single leak, independent of N.ciaranj commentedon Sep 4, 2024
Hmm, I don’t have that project to hand currently. However, I may have just assumed that that single ‘leak’ was just something lazily initialised by angular, so didn’t treat it as a leak as it wasn’t leading to any memory growth?
Emil-Blomquist commentedon Sep 5, 2024
Yea you might right, perhaps I'm being a little pedantic!