Skip to content

Commit ad21ee2

Browse files
crisbetoandrewseguin
authored andcommitted
fix(table): not clearing some internal references on destroy (#16051)
`CdkTable` keeps track of various definitions internally in order to render itself, however some of them weren't being cleared on destroy which could lead to memory leaks. These changes add some extra logic to clear the tracked references. (cherry picked from commit caf979a)
1 parent 99e7782 commit ad21ee2

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/cdk/table/table.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,23 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
611611
}
612612

613613
ngOnDestroy() {
614-
this._rowOutlet.viewContainer.clear();
615-
this._noDataRowOutlet.viewContainer.clear();
616-
this._headerRowOutlet.viewContainer.clear();
617-
this._footerRowOutlet.viewContainer.clear();
618-
619-
this._cachedRenderRowsMap.clear();
614+
[
615+
this._rowOutlet.viewContainer,
616+
this._headerRowOutlet.viewContainer,
617+
this._footerRowOutlet.viewContainer,
618+
this._cachedRenderRowsMap,
619+
this._customColumnDefs,
620+
this._customRowDefs,
621+
this._customHeaderRowDefs,
622+
this._customFooterRowDefs,
623+
this._columnDefsByName
624+
].forEach(def => {
625+
def.clear();
626+
});
620627

628+
this._headerRowDefs = [];
629+
this._footerRowDefs = [];
630+
this._defaultRowDef = null;
621631
this._onDestroy.next();
622632
this._onDestroy.complete();
623633

0 commit comments

Comments
 (0)