angular: Ivy doesn't clear the component after the component is destroyed.

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is 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.

  1. The homepage will redirect to LoginComponent Screenshot from 2020-02-26 07-14-29

  2. Click a button will navigate to HelloComponent.

  3. in chrome devtools memory tab, GC->take heap snapshot, but can still find LoginComponent in the heap. And it is retained by an InternalNode object. Screenshot from 2020-02-26 07-15-54

πŸ”¬ 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)

Commits related to this issue

Most upvoted comments

@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 one RootContext 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.

  1. navigate to homepage. Screenshot from 2020-02-25 18-38-12

  2. Then click button click, will navigate to /hello. Take a memory snapshot, we can find that LoginComponent is still in the memory, it is retained by the app-login HTMLElement, and this HTMLElement has already been removed from it’s parent (app-root), and the reason that this app-login HTMLElement is still in the memory is the element is retained by an InternalNode object, in my understanding, this InternalNode is ready for GC, but Chrome consider it is not necessary to destroy it at that time.

Screenshot from 2020-02-25 18-44-43

  1. Then click button hello1, will navigate to /hello1, Take a memory snapshot again, we can find that the LoginComponent is gone. And the HTMLElement app-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.