I wrote a broadcast picture with setInterval, but after running it for a period of time, the browser crashed.

The

code does not report an error, and the browser crashes after running for a period of time. The specific code is as follows:

carousel () {

    let self = this;
    if(!window.timer){
      this.carouselText = "";
      let oLen = this.substationTree.length;
      window.timer = setInterval(() => {
        self.carouselIndex = self.carouselIndex < oLen - 1 ? self.carouselIndex + 1 : 0;
        self.$set(self.substationTree[self.carouselIndex], "selected", true);
        self.selectedNode = Object.assign({}, self.substationTree[self.carouselIndex]);
        self.clickOnTreeNode([self.substationTree[self.carouselIndex]]);
      }, 5000);
    }else {
      this.carouselText = "";
      window.clearInterval(window.timer);
      window.timer = undefined;
    }
  }
May.22,2021

else {
      this.carouselText = "";
      window.clearInterval(window.timer);
      window.timer = undefined;
      setInterval(code, milliseconds);
    }

who will turn off this timer on the last line of this sentence?


it is correct that there is no problem with the above code. My problem is that I have to load the wiring diagram once after the rotation, and the wiring diagram will be refreshed each time, resulting in too much memory, which has been solved

.
Menu