Skip to content

Commit 56a333a

Browse files
committed
fix(cdk/tree): retainining previous objects
fixes component retaining old data in memory even when its not used causing memory usage to increase fixes #30322
1 parent 1b3c42e commit 56a333a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/cdk/tree/tree.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,10 @@ export class CdkTree<T, K = T>
10101010
return observableOf([...nodes]);
10111011
}
10121012

1013+
// clear previously generated data so we don't keep end up retaining data overtime causing
1014+
// memory leaks.
1015+
this._clearPreviousCache();
1016+
10131017
return observableOf(...nodes).pipe(
10141018
concatMap(node => {
10151019
const parentKey = this._getExpansionKey(node);
@@ -1125,8 +1129,9 @@ export class CdkTree<T, K = T>
11251129
return;
11261130
}
11271131

1128-
this._parents.clear();
1129-
this._ariaSets.clear();
1132+
// clear previously generated data so we don't keep end up retaining data overtime causing
1133+
// memory leaks.
1134+
this._clearPreviousCache();
11301135

11311136
for (let index = 0; index < flattenedNodes.length; index++) {
11321137
const dataNode = flattenedNodes[index];
@@ -1163,6 +1168,13 @@ export class CdkTree<T, K = T>
11631168
callback(toToggle);
11641169
}
11651170
}
1171+
1172+
/** Clears the maps we use to store parents, level & aria-sets in. */
1173+
private _clearPreviousCache() {
1174+
this._parents.clear();
1175+
this._levels.clear();
1176+
this._ariaSets.clear();
1177+
}
11661178
}
11671179

11681180
/**

0 commit comments

Comments
 (0)