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
LoginComponent
in the heap. And it is retained by anInternalNode
object.
π¬ 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
RootContext
Where more than oneRootContext
objects 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
Login
2.Hello
3.Hello1
Demo steps.
navigate to homepage.
Then click button
click
, will navigate to/hello
. Take a memory snapshot, we can find thatLoginComponent
is still in the memory, it is retained by theapp-login
HTMLElement, and this HTMLElement has already been removed from itβs parent (app-root
), and the reason that thisapp-login
HTMLElement is still in the memory is the element is retained by anInternalNode
object, in my understanding, thisInternalNode
is 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 theLoginComponent
is gone. And the HTMLElementapp-login
is 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.