Chrome setInterval crashes at 10,000 ms

I work on Javascript stopwatch applications and works in every browser but Chrome.

Here is the fiddle: http://jsfiddle.net/djwelsh/Sxyy8/

In theory, this is very simple. When you press the Start button , the time in milliseconds is recorded and starts setInterval. At each interval, the start time is subtracted from the current era. This leaves us with a value in milliseconds that is converted to h:m:s:csand displayed on the page.


Problem

My problem is with Chrome. Each time the timer reaches 10,000 ms, the tab crashes with the message "Aw, snap".

One strange aspect is that the crash is still happening if you click Stop , wait a few seconds, and then click Start again . This, apparently, indicates that this is a memory problem - something is filling up to such an extent that it can no longer be held and overflowed. But a memory check in both dev tools and the resource monitor shows nothing at all.


Possible solutions

The problem can be prevented by changing the interval value to a number greater than 100 ms (by default I want to use 50). For some reason, it can also be prevented by registering timer values ​​in the console.

, , , , , . , , .

, , , , ( Chrome - ).

, , , ; . , SO.

( ), . 10000: http://jsfiddle.net/djwelsh/Sxyy8/7/


@Akhlesh, . : http://jsfiddle.net/djwelsh/Sxyy8/18/


, , ( ), - , , .

+4
1

, , , .

  var uTime,uNow;
  //Update function will use same variable to initialize time and now 
  updateTime: function () {
     uNow = Date.now();
     oO.milliseconds = uNow - oO.epoch;
     uTime = oO.getTimeObject(oO.milliseconds);
     oO.el.testClock.text('' + uTime.h + ':' + uTime.m + ':' + uTime.s + ':' + uTime.ms + '');
  }

, , GC .

+1

Source: https://habr.com/ru/post/1545310/


All Articles