Skip to content

Commit 14e6f6b

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 dc859fe commit 14e6f6b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/cdk/table/table.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,23 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
447447
}
448448

449449
ngOnDestroy() {
450-
this._rowOutlet.viewContainer.clear();
451-
this._headerRowOutlet.viewContainer.clear();
452-
this._footerRowOutlet.viewContainer.clear();
453-
454-
this._cachedRenderRowsMap.clear();
450+
[
451+
this._rowOutlet.viewContainer,
452+
this._headerRowOutlet.viewContainer,
453+
this._footerRowOutlet.viewContainer,
454+
this._cachedRenderRowsMap,
455+
this._customColumnDefs,
456+
this._customRowDefs,
457+
this._customHeaderRowDefs,
458+
this._customFooterRowDefs,
459+
this._columnDefsByName
460+
].forEach(def => {
461+
def.clear();
462+
});
455463

464+
this._headerRowDefs = [];
465+
this._footerRowDefs = [];
466+
this._defaultRowDef = null;
456467
this._onDestroy.next();
457468
this._onDestroy.complete();
458469

0 commit comments

Comments
 (0)