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(Tree): Memory leak when changing data source #30322

Open
1 task done
ilchenkob opened this issue Jan 14, 2025 · 0 comments · May be fixed by #30431
Open
1 task done

bug(Tree): Memory leak when changing data source #30322

ilchenkob opened this issue Jan 14, 2025 · 0 comments · May be fixed by #30431
Labels
area: cdk/tree P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@ilchenkob
Copy link

ilchenkob commented Jan 14, 2025

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

17.2.2

Description

After upgrading Angular project from v17 to v18, our team noticed a memory leak in the app. After profiling, I found that mat-tree component holds references to old node objects after updating the data source, which prevents them from being collected by GC.

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-ujvrwarq?file=src%2Fmain.ts
Steps to reproduce:

  1. Go to DevTools -> Memory -> Heap Snapshot
  2. Take a heap snapshot
  3. Click Get Data several times
  4. Take a heap snapshot
  5. Repeat steps 3 and 4
  6. Compare heap snapshots

Expected Behavior

Old Node objects must be collected by GC. The memory heap should contain only those objects that are present in the tree.

Actual Behavior

Node objects are never collected by GC. The size of the memory heap groves over time as node objects accumulate in memory.

Image

Environment

  • Angular: 18.2.5
  • CDK/Material: 18.2.5
  • Browser(s): Google Chrome Version 131.0.6778.205 (Official Build) (64-bit)
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
@ilchenkob ilchenkob added the needs triage This issue needs to be triaged by the team label Jan 14, 2025
@ilchenkob ilchenkob changed the title bug(Tree): Memory leak on data source changes bug(Tree): Memory leak when changing data source Jan 14, 2025
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: cdk/tree and removed needs triage This issue needs to be triaged by the team labels Jan 21, 2025
naaajii added a commit to naaajii/components that referenced this issue Feb 1, 2025
fixes component retaining old data in memory even when its not used causing memory usage to increase

fixes angular#30322
@naaajii naaajii linked a pull request Feb 1, 2025 that will close this issue
naaajii added a commit to naaajii/components that referenced this issue Feb 26, 2025
fixes component retaining old data in memory even when its not used causing memory usage to increase

fixes angular#30322
naaajii added a commit to naaajii/components that referenced this issue Feb 26, 2025
fixes component retaining old data in memory even when its not used causing memory usage to increase

fixes angular#30322
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/tree P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants