From 471b452dcf36bac27135d040c0366faa5eeaad65 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Fri, 17 May 2019 16:11:26 +0200 Subject: [PATCH] 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. --- src/cdk/table/table.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cdk/table/table.ts b/src/cdk/table/table.ts index 1dabd49ad286..10ed8d24ea6e 100644 --- a/src/cdk/table/table.ts +++ b/src/cdk/table/table.ts @@ -483,13 +483,23 @@ export class CdkTable implements AfterContentChecked, CollectionViewer, OnDes } ngOnDestroy() { - this._rowOutlet.viewContainer.clear(); - this._noDataRowOutlet.viewContainer.clear(); - this._headerRowOutlet.viewContainer.clear(); - this._footerRowOutlet.viewContainer.clear(); - - this._cachedRenderRowsMap.clear(); + [ + this._rowOutlet.viewContainer, + this._headerRowOutlet.viewContainer, + this._footerRowOutlet.viewContainer, + this._cachedRenderRowsMap, + this._customColumnDefs, + this._customRowDefs, + this._customHeaderRowDefs, + this._customFooterRowDefs, + this._columnDefsByName + ].forEach(def => { + def.clear(); + }); + this._headerRowDefs = []; + this._footerRowDefs = []; + this._defaultRowDef = null; this._onDestroy.next(); this._onDestroy.complete();