Skip to content

Commit 471b452

Browse files
committed
fix(table): not clearing some internal references on destroy
`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.
1 parent ba11a0b commit 471b452

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
@@ -483,13 +483,23 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
483483
}
484484

485485
ngOnDestroy() {
486-
this._rowOutlet.viewContainer.clear();
487-
this._noDataRowOutlet.viewContainer.clear();
488-
this._headerRowOutlet.viewContainer.clear();
489-
this._footerRowOutlet.viewContainer.clear();
490-
491-
this._cachedRenderRowsMap.clear();
486+
[
487+
this._rowOutlet.viewContainer,
488+
this._headerRowOutlet.viewContainer,
489+
this._footerRowOutlet.viewContainer,
490+
this._cachedRenderRowsMap,
491+
this._customColumnDefs,
492+
this._customRowDefs,
493+
this._customHeaderRowDefs,
494+
this._customFooterRowDefs,
495+
this._columnDefsByName
496+
].forEach(def => {
497+
def.clear();
498+
});
492499

500+
this._headerRowDefs = [];
501+
this._footerRowDefs = [];
502+
this._defaultRowDef = null;
493503
this._onDestroy.next();
494504
this._onDestroy.complete();
495505

0 commit comments

Comments
 (0)