Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(core): clean up TestabilityRegistry on platform destroy to avoid …
…memory leaks

Closes #13725
  • Loading branch information
Dzmitry Shylovich committed Feb 28, 2017
commit b9f6585b162a0ab2e03bfa521bbc123d94a64e62
1 change: 1 addition & 0 deletions modules/@angular/core/src/application_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export class PlatformRef_ extends PlatformRef {
}
this._modules.slice().forEach(module => module.destroy());
this._destroyListeners.forEach(listener => listener());
this._injector.get(TestabilityRegistry).destroy();
this._destroyed = true;
}

Expand Down
8 changes: 8 additions & 0 deletions modules/@angular/core/src/testability/testability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ export class TestabilityRegistry {
findTestabilityInTree(elem: Node, findInAncestors: boolean = true): Testability {
return _testabilityGetter.findTestabilityInTree(this, elem, findInAncestors);
}

destroy(): void {
this._applications.clear();
_testabilityGetter.onDestroy();
}
}

/**
Expand All @@ -158,6 +163,7 @@ export interface GetTestability {
addToWindow(registry: TestabilityRegistry): void;
findTestabilityInTree(registry: TestabilityRegistry, elem: any, findInAncestors: boolean):
Testability;
onDestroy(): void;
}

class _NoopGetTestability implements GetTestability {
Expand All @@ -166,6 +172,8 @@ class _NoopGetTestability implements GetTestability {
Testability {
return null;
}

onDestroy(): void {}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions modules/@angular/platform-browser/src/browser/testability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ export class BrowserGetTestability implements GetTestability {
}
return this.findTestabilityInTree(registry, getDOM().parentElement(elem), true);
}

onDestroy(): void {
delete global.getAngularTestability;
delete global.getAllAngularTestabilities;
delete global.getAllAngularRootElements;
delete global.frameworkStabilizers;
}
}
1 change: 1 addition & 0 deletions tools/public_api_guard/core/typings/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ export declare class Testability implements PublicTestability {
/** @experimental */
export declare class TestabilityRegistry {
constructor();
destroy(): void;
findTestabilityInTree(elem: Node, findInAncestors?: boolean): Testability;
getAllRootElements(): any[];
getAllTestabilities(): Testability[];
Expand Down