File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff 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/**
You can’t perform that action at this time.
0 commit comments