How can I hundle interval memory leak in angular 10?

Viewed 98

I have one page that will be run for the whole day and I also need to refresh the data every 5 seconds.

here is code=>

    private ngUnsubscribe = new Subject();
    
    selectData(){
        this.selectData$= interval(5000).pipe(
          takeUntil(this.ngUnsubscribe),
          startWith(0),
          switchMap(_ => forkJoin([ getAll1(),
            getAll2()])),
          multicast(() => new Subject())
        ) as ConnectableObservable<any>; 
    
        this.dataBinding();
        this.selectData$.connect();    
      }
      
      dataBinding(){
        this.selectData$
        .pipe(
          takeUntil(this.ngUnsubscribe)
        ).subscribe( (res: any) => {  
          let result1 = res[0] as result;
          let result2 = res[1] as result;
    
          
        })
      }
      
       ngOnInit(): void {
        this.selectData();
      }
      
      ngOnDestroy():void{
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete(); 
      }

The problem is this page is keeping up the memory usage. After I open this page and leave for an hour, I got the crush page error and message " out of memory"

Is there any wrong at my code or Is there any way to solve this issue?

Refresh the page(Like F5) can solve this issue? I already search for reloading the page but not work like F5. How?

0 Answers
Related