Как освободить ресурсы во время роботы rxjs interval
У я меня есть рабочий CountDown таймер, который ведет обратный отсчет до определенной даты.
ngOnDestroy() {
this.interv.unsubscribe();
}
getDays(t) {
return Math.floor( t / (1000 * 60 * 60 * 24) );
}
getHours(t) {
return Math.floor( (t / (1000 * 60 * 60)) % 24 );
}
getMinutes(t) {
return Math.floor( (t / 1000 / 60) % 60 );
}
getSeconds(t) {
return Math.floor( (t / 1000) % 60 );
}
addZeros(n, needLength = null) {
needLength = needLength || 2;
n = String(n);
while (n.length < needLength) {
n = "0" + n;
}
return n
}
decriseTime(time) {
this._trialEndsAt = time;
this.interv = interval(1000).pipe(
map((x) => {this._diff = Date.parse(this._trialEndsAt) - Date.parse(new Date().toString());
})).subscribe((x) => {
this._days = this.getDays(this._diff);
this._hours = this.getHours(this._diff);
this._minutes = this.getMinutes(this._diff);
this._seconds = this.getSeconds(this._diff);
this.days = this.addZeros(this._days);
this.hours = this.addZeros(this._hours);
this.minutes = this.addZeros(this._minutes);
this.seconds = this.addZeros(this._seconds);
});
return '<span>' + this.days + '<span>дней</span></span>:<span>' + this.hours + '<span>часов</span></span>:<span>' + this.minutes + '<span>минут</span></span>:<span>' + this.seconds + '<span>секунд</span></span>';
}
<div class="decriseTimer" [innerHTML]="decriseTime(slide.dateCountDown)"></div>
Но как только я запускаю страницу, приложение стремительно начинает накапливать данные, и со временем виснет комп. Как здесь правильно освободить ресурсы, чтобы выделенная память не уходила в гигабайты?