What happens if all setTimeout IDs are used?

Calling the setTimeout function will return an integer ID so that clearTimeout can be called with that ID.

What happens if setTimeout gets called more times than there are positive integers in JavaScript? Is there a security issue?

Answers


Found the relevant code in Chrome:

static int timeoutId()
{
    static int lastUsedTimeoutId = 0;
    ++lastUsedTimeoutId;
    // Avoid wraparound going negative on us.
    if (lastUsedTimeoutId <= 0)
        lastUsedTimeoutId = 1;
    return lastUsedTimeoutId;
}

Thus, Last ID will be just 1 after no positive integers remaining.


You'll run out of memory (or some other resource) long before that happens. Javascript numbers are 64 bit floats, which can accurately represent integers up to 2^52, which means it takes 32 petabytes of memory to even hold that many IDs, let alone accompanying objects or tasks.


On my 32 bit windows 7 system with Chrome 21, the tab with the page crashed after about 4295063. But it was only the tab. I closed that tab and everything else was working normally.

Opera 12 the script runs slower and slower.

Firefox complains about that the script is taking to much time.

You can test for yourself: http://jsfiddle.net/some/r58s8/


Need Your Help

How to combine wildcard and not selectors in CSS

html css css3

Imagine you have a div in one of three possible states.

Java EE Application Startup Failure

java-ee servlets startup ejb-3.1

Is there any method to prevent a Java EE application from starting if an exception occurs during application initialization? I'm basically looking for a way to cause the application to enter a "j2ee.