Merge pull request #925 from SonicWizard/master

fix memory leak by clearing interval on destroy hook
This commit is contained in:
Justin Langston 2018-05-02 10:19:04 -04:00 committed by GitHub
commit b024e7e2d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,17 +20,19 @@ export class LatestBlocksComponent {
@Input() public numBlocks: number;
@Input() public showAllBlocksButton: boolean;
@Input() public showTimeAs: string;
private reloadInterval: any;
constructor(private blocksProvider: BlocksProvider, private navCtrl: NavController, ngZone: NgZone) {
this.loadBlocks();
const seconds: number = 15;
ngZone.runOutsideAngular(() => {
setInterval(
this.reloadInterval = setInterval(
function (): void {
ngZone.run(function (): void {
this.loadBlocks.call(this);
}.bind(this));
}.bind(this),
1000 * 30
1000 * seconds
);
});
}
@ -63,4 +65,8 @@ export class LatestBlocksComponent {
public goToBlocks(): void {
this.navCtrl.push(BlocksPage);
}
private ngOnDestroy(): void {
clearInterval(this.reloadInterval);
}
}