fix memory leak by clearing interval on destroy hook
This commit is contained in:
parent
ca69a445ff
commit
31de1cb133
@ -20,17 +20,19 @@ export class LatestBlocksComponent {
|
|||||||
@Input() public numBlocks: number;
|
@Input() public numBlocks: number;
|
||||||
@Input() public showAllBlocksButton: boolean;
|
@Input() public showAllBlocksButton: boolean;
|
||||||
@Input() public showTimeAs: string;
|
@Input() public showTimeAs: string;
|
||||||
|
private reloadInterval: any;
|
||||||
|
|
||||||
constructor(private blocksProvider: BlocksProvider, private navCtrl: NavController, ngZone: NgZone) {
|
constructor(private blocksProvider: BlocksProvider, private navCtrl: NavController, ngZone: NgZone) {
|
||||||
this.loadBlocks();
|
this.loadBlocks();
|
||||||
|
const seconds: number = 15;
|
||||||
ngZone.runOutsideAngular(() => {
|
ngZone.runOutsideAngular(() => {
|
||||||
setInterval(
|
this.reloadInterval = setInterval(
|
||||||
function (): void {
|
function (): void {
|
||||||
ngZone.run(function (): void {
|
ngZone.run(function (): void {
|
||||||
this.loadBlocks.call(this);
|
this.loadBlocks.call(this);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
1000 * 30
|
1000 * seconds
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -63,4 +65,8 @@ export class LatestBlocksComponent {
|
|||||||
public goToBlocks(): void {
|
public goToBlocks(): void {
|
||||||
this.navCtrl.push(BlocksPage);
|
this.navCtrl.push(BlocksPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ngOnDestroy(): void {
|
||||||
|
clearInterval(this.reloadInterval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user