angular: Ivy doesn't clear the component after the component is destroyed.
π bug report
Affected Package
The issue is caused by package @angular/coreIs this a regression?
Yes, the previous version in which this bug was not present was: ....Description
A clear and concise description of the problem...The reproduce repo is here, https://github.com/JiaLiPassion/ivy-memory-leak
Basically we have two routes with two components. Login and Hello component.
-
The homepage will redirect to
LoginComponent
-
Click a button will navigate to
HelloComponent. -
in chrome devtools memory tab, GC->take heap snapshot, but can still find
LoginComponentin the heap. And it is retained by anInternalNodeobject.
π¬ Minimal Reproduction
https://github.com/JiaLiPassion/ivy-memory-leak
π₯ Exception or Error
π Your Environment
Angular Version:
I assume this issue related to this one https://github.com/angular/angular/issues/35148, but I updated to the newest version `9.1.0-next.1`, but the issue still exists.
Anything else relevant?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 23 (18 by maintainers)
@JiaLiPassion Thank you for such a nice and simple repro. It makes a huge difference!
I have investigated this a bit but it seems to be something related to
RootContextWhere more than oneRootContextobjects get created and retained. (One for each login) Because they donβt get released the components stay around.I have updated the reproduce repo, https://github.com/JiaLiPassion/ivy-memory-leak/tree/multi-route maybe this is not a bug, maybe this is how chrome handle GC? In the updated demo, there are 3 routes. 1
Login2.Hello3.Hello1Demo steps.
navigate to homepage.
Then click button
click, will navigate to/hello. Take a memory snapshot, we can find thatLoginComponentis still in the memory, it is retained by theapp-loginHTMLElement, and this HTMLElement has already been removed from itβs parent (app-root), and the reason that thisapp-loginHTMLElement is still in the memory is the element is retained by anInternalNodeobject, in my understanding, thisInternalNodeis ready for GC, but Chrome consider it is not necessary to destroy it at that time.hello1, will navigate to/hello1, Take a memory snapshot again, we can find that theLoginComponentis gone. And the HTMLElementapp-loginis also gone.So maybe this is not an issue? But I tried in some more complex real project, the first component will not gone even I navigate to several other routes.