Skip to content

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

Closed
@ilchenkob

Description

@ilchenkob

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/tree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions