Skip to content

fix(tooltip): leaking TooltipComponent references #9109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 23, 2017

Fixes references to each of the TooltipComponent instances (one per opened tooltip) created by MatTooltip not being cleaned up on close. The issue comes from the fact that we're passing in the ViewContainerRef which ends up retaining the references until it is destroyed, which is problematic, because the tooltip could be attached to a very long-lived view container (e.g. inside an app's navigation). In this case we can get away with not passing in the view container, because the tooltip component is internal and we manipulate it directly through the tooltip trigger anyway.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 23, 2017
@jelbourn
Copy link
Member

This could be problematic for testing because the view container determines when change detection happens for the tooltip content. Without specifying that, doing fixture.detectChanges() on the view that physically contains the tooltip wouldn't necessarily update its contents.

Why does the view container retain the reference to the tooltip component after it has been destroyed? Is this something that could be fixed in core?

@crisbeto
Copy link
Member Author

I was under the impression that detectChanges in tests just runs change detection over the entire app, but I'm not too familiar with the internals. Also I'm not sure why the references were being retained by the container, but that's where the heap snapshot was pointing. It's possible that there's something wrong in the overlay/portal that's preventing it from being collected, but I haven't been able to pinpoint it and we don't have issues in any of the other overlays as far as I can tell.

@jelbourn
Copy link
Member

I'll get someone from the core team to take a look next week

@jelbourn
Copy link
Member

@crisbeto think you could make a minimal repro of the ViewContainer maintaining a reference after destroying the ComponentRef?

@crisbeto crisbeto force-pushed the tooltip-component-leak branch from 055e2b1 to 918bcc9 Compare April 20, 2018 13:58
@crisbeto crisbeto force-pushed the tooltip-component-leak branch 2 times, most recently from e2aa1f7 to 3456d63 Compare May 25, 2018 20:19
@mmalerba mmalerba added aaa and removed aaa labels Apr 25, 2019
@jelbourn jelbourn added the P2 The issue is important to a large percentage of users, with a workaround label Jun 20, 2019
@jelbourn
Copy link
Member

@crisbeto let's try this in ivy and see if the behavior changes, maybe some further debugging in the framework

@crisbeto crisbeto force-pushed the tooltip-component-leak branch from 3456d63 to cdd80ed Compare July 7, 2019 15:07
Fixes references to each of the `TooltipComponent` instances (one per opened tooltip) created by `MatTooltip` not being cleaned up. The issue comes from the fact that we're passing in the `ViewContainerRef` which ends up retaining the references until it is destroyed. This is problematic, because the tooltip could be attached to a very long-lived view container (e.g. inside the app navigation).
@crisbeto crisbeto force-pushed the tooltip-component-leak branch from cdd80ed to c449fba Compare March 24, 2020 19:54
@andrewseguin
Copy link
Contributor

I suspect this PR can be closed, Ivy seems to have resolved the issue of holding onto old references. See this comment for details: #10397 (comment)

@crisbeto crisbeto closed this Jun 12, 2020
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants