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
Seeing detached elements in a memory snapshot when I navigate from one route to another #58828
Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
I am using Angular router module and trying to fix a memory leak problem.
In a sample application, I have 2 routes and I am in Page1.
Once I click anywhere in Page1 component and go to Page2 via routerLink, I can see Page1 component as a detached element in memory snapshot.
This is a screenshot.
I am in test-2 page now but can see app-test1 component is detached.
I tried in different Angular versions (12, 16, 19) and the behavior was exactly same.
Of course, I don't have any observables, pipes, services, ... My components are clean and it doesnt have any extra codes in component.ts files.
And I used only a and div tags in html.
It doesnt have any parent-child relationship too.
Can you please help me how I can fix this? or is this expected behavior in web applications?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Click Test 1 text in the first page. (route is /test-1)
Navigate to /test-2 by clicking GoTest2
Open chrome DevTools and take a snapshot after garbage collection
You can see app-test1 component is detached which is not displayed in /test-2 route.
Please take a look of this application and let me know how we can avoid this probelm
With the extension disabled (e.g. in Incognito mode) I don't see the same retainer, nor is it very persistent: opening DevTools caused it to be dropped.
@JeanMeche , @JoostK
Can you please let me know how to take a snapshot while running in production mode?
Is it same as we do in dev mode? (with chrome devtools)
Hi @JoostK , @JeanMeche
We are facing same issue again when we use angular material.
Currently, we are using matMenu and we can see some elements related to mantMenu are detached.
Here is an example link. https://stackblitz.com/edit/v7o3ky-av3em4?file=package.json
if I click some menu items and go to test2 route, I can see menu elements are detached.
I followed the same steps you mentioned above. I did not open devtools while I am testing on the page.
Could you please help me on this?
or is this an open issue when we use angular material?
@JeanMeche, does it mean we will see same behavior in the pages where we use animation module?
And we are using angular 12 now in our project.
Will this fix (angular/components#30057) work for angular 12?
I wonder if it will work for latest Angular version.
Activity
JoostK commentedon Nov 22, 2024
Without runnable reproduction this won't be actionable to us.
Tomas-CloudIQ commentedon Nov 25, 2024
Hi @JoostK , I made a simple sample angular app in StackBlitz and here is the link.
https://stackblitz.com/edit/stackblitz-starters-bztgsm?description=An%20angular-cli%20project%20based%20on%20@angular/animations,%20@angular/common,%20@angular/compiler,%20@angular/core,%20@angular/forms,%20@angular/platform-browser,%20@angular/platform-browser-dynamic,%20@angular/router,%20core-js,%20rxjs,%20tslib%20and%20zone.js&file=src%2Fapp.config.ts,src%2Fapp.routes.ts,src%2Fcomponents%2Froot%2Froot.component.html,src%2Fcomponents%2Froot%2Froot.component.ts,src%2Fcomponents%2Ftest1%2Ftest1.component.html,src%2Fcomponents%2Ftest1%2Ftest1.component.ts,src%2Fcomponents%2Ftest2%2Ftest2.component.html,src%2Fcomponents%2Ftest2%2Ftest2.component.ts,src%2Fmain.ts&template=node&title=Angular%20Starter
Reproduce steps.
Click Test 1 text in the first page. (route is /test-1)
Navigate to /test-2 by clicking GoTest2
Open chrome DevTools and take a snapshot after garbage collection

You can see app-test1 component is detached which is not displayed in /test-2 route.
Please take a look of this application and let me know how we can avoid this probelm
JoostK commentedon Nov 25, 2024
Thanks, that does show a retainer from Angular DevTools:
Heap-20241125T230037.heapsnapshot.zip
With the extension disabled (e.g. in Incognito mode) I don't see the same retainer, nor is it very persistent: opening DevTools caused it to be dropped.
JoostK commentedon Nov 25, 2024
So the question is, are you experiencing the leak in production mode/without DevTools too?
7 remaining items
Tomas-CloudIQ commentedon Nov 25, 2024
@JeanMeche , @JoostK
Can you please let me know how to take a snapshot while running in production mode?
Is it same as we do in dev mode? (with chrome devtools)
JeanMeche commentedon Nov 26, 2024
Yes, it's the same. It's your app that needs to be build for production.
Tomas-CloudIQ commentedon Nov 27, 2024
Thanks for your reply.
@JoostK , I have one more questions from your reply.
#58828 (comment)
How can I find that retainer comes from dev tools?
Tomas-CloudIQ commentedon Nov 27, 2024
Hi @JoostK , @JeanMeche

We are facing same issue again when we use angular material.
Currently, we are using matMenu and we can see some elements related to mantMenu are detached.
Here is an example link.
https://stackblitz.com/edit/v7o3ky-av3em4?file=package.json
if I click some menu items and go to test2 route, I can see menu elements are detached.
I followed the same steps you mentioned above. I did not open devtools while I am testing on the page.
Could you please help me on this?
or is this an open issue when we use angular material?
JeanMeche commentedon Nov 27, 2024
So, the source of the leak is actually our animation module.
This pretty much reminds me of #54149, where matSort had similar leaks. It was addressed very recently by angular/components#30057.
Maybe @crisbeto can give some thoughts on this.
Tomas-CloudIQ commentedon Nov 27, 2024
@JeanMeche, does it mean we will see same behavior in the pages where we use animation module?
And we are using angular 12 now in our project.
Will this fix (angular/components#30057) work for angular 12?
I wonder if it will work for latest Angular version.
JeanMeche commentedon Nov 27, 2024
v12 is outside of the support scope. Please have a look at our support policy.
JoostK commentedon Nov 28, 2024
The animations memory leak is mostly benign, see #47748 (comment).
Tomas-CloudIQ commentedon Nov 28, 2024
@JeanMeche , was this fix released to Angular 17 latest versions now?
JeanMeche commentedon Nov 28, 2024
Those fixes don't land in LTS versions but only the active one (currently v19).
Tomas-CloudIQ commentedon Nov 28, 2024
@JeanMeche, So it was released only to v19?
And do you have any plans to introduce this fix to v17?
JeanMeche commentedon Dec 11, 2024
We don't do any backport fix beside security fixes.
I think we can close this per above. The was no repro provided that exhibits a real leak.
angular-automatic-lock-bot commentedon Jan 11, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.