From f6b5078ea19106bdf921713b368b222363772990 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Thu, 21 Aug 2025 09:08:45 +0200 Subject: [PATCH] fix(cdk/tree): resolve memory leak Fixes a subscription that was never being cleaned up in the tree. Also completes a few subjects. --- src/cdk/tree/tree.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cdk/tree/tree.ts b/src/cdk/tree/tree.ts index 6c9f225db6e6..8f086ee758c9 100644 --- a/src/cdk/tree/tree.ts +++ b/src/cdk/tree/tree.ts @@ -282,6 +282,10 @@ export class CdkTree ngOnDestroy() { this._nodeOutlet.viewContainer.clear(); + this._nodes.complete(); + this._keyManagerNodes.complete(); + this._nodeType.complete(); + this._flattenedNodes.complete(); this.viewChange.complete(); this._onDestroy.next(); this._onDestroy.complete(); @@ -1403,6 +1407,7 @@ export class CdkTreeNode implements OnDestroy, OnInit, TreeKeyManagerI distinctUntilChanged(), takeUntil(this._destroyed), ) + .pipe(takeUntil(this._destroyed)) .subscribe(() => this._changeDetectorRef.markForCheck()); this._tree._setNodeTypeIfUnset(this._type); this._tree._registerNode(this);