Skip to content

Commit

Permalink
fix(table): not clearing some internal references on destroy (#16051)
Browse files Browse the repository at this point in the history
`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)
  • Loading branch information
crisbeto authored and andrewseguin committed Jan 13, 2022
1 parent 99e7782 commit ad21ee2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/cdk/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,23 @@ export class CdkTable<T> 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();

Expand Down

0 comments on commit ad21ee2

Please sign in to comment.