Skip to content
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

bug(MatMenu): Memory Leak in MatMenu and MatAutocomplete #29696

Closed
1 task
jingglang opened this issue Sep 5, 2024 · 1 comment · Fixed by #29709
Closed
1 task

bug(MatMenu): Memory Leak in MatMenu and MatAutocomplete #29696

jingglang opened this issue Sep 5, 2024 · 1 comment · Fixed by #29709
Labels
area: material/autocomplete area: material/menu area: material/select needs investigation A member of the team needs to do further investigation to determine the root cause

Comments

@jingglang
Copy link

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

There are detached elements in memory snapshot after clicking the menu or autocomplete to show the dropdowns. It can be replicated in https://material.angular.io web site.

Reproduction

Steps to reproduce:

  1. Go to https://material.angular.io/components/menu/overview menu component page.
  2. Click a menu to show the drop down. Then click the API tab to destroy the menu component. Repeat this steps several times.
  3. Go to landing page. The menu-related memory should've been destroyed.
  4. Take a memory snapshot.

Do similar steps to reproduce memory leak for Autocomplete.

Expected Behavior

There should be no memory allocation related to MatMenu or MatAutocomplete because the landing page doesn't have them.

Actual Behavior

There are many detached elemets that should've been garbage collected.

Screenshot_20240905_150759

Environment

  • Angular: 18
  • CDK/Material: 18
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Linux 6.8.0-40-generic mdProgressBar #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
@jingglang jingglang added the needs triage This issue needs to be triaged by the team label Sep 5, 2024
@crisbeto crisbeto added needs investigation A member of the team needs to do further investigation to determine the root cause area: material/autocomplete area: material/menu area: material/select and removed needs triage This issue needs to be triaged by the team labels Sep 9, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 9, 2024
The `OverlayRef` was triggering an `afterEachRender` and passing in an `EnvironmentInjector`. Under the hood this uses a `DestroyRef` that is never destroyed, because the `EnvironmentInjector` is almost never destroyed.

These changes add an explicit `destroy` call to avoid the issue.

Fixes angular#29696.
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 9, 2024
The `OverlayRef` was triggering an `afterEachRender` and passing in an `EnvironmentInjector`. Under the hood this uses a `DestroyRef` that is never destroyed, because the `EnvironmentInjector` is almost never destroyed.

These changes add an explicit `destroy` call to avoid the issue.

Fixes angular#29696.
crisbeto added a commit that referenced this issue Sep 10, 2024
The `OverlayRef` was triggering an `afterEachRender` and passing in an `EnvironmentInjector`. Under the hood this uses a `DestroyRef` that is never destroyed, because the `EnvironmentInjector` is almost never destroyed.

These changes add an explicit `destroy` call to avoid the issue.

Fixes #29696.

(cherry picked from commit 3a62ab1)
@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 Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/autocomplete area: material/menu area: material/select needs investigation A member of the team needs to do further investigation to determine the root cause
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants