Skip to content

Commit

Permalink
fix(table): not clearing some internal references on destroy
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.
  • Loading branch information
crisbeto committed May 17, 2019
1 parent dc859fe commit 14e6f6b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/cdk/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,23 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
}

ngOnDestroy() {
this._rowOutlet.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 14e6f6b

Please sign in to comment.