Closed
Description
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:
- Go to DevTools -> Memory -> Heap Snapshot
- Take a heap snapshot
- Click Get Data several times
- Take a heap snapshot
- Repeat steps 3 and 4
- 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.
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