Search code examples
javascriptnode.jsbrowserruntimestack-overflow

Does the set timeout web API have no memory limit?


The setTimeout call removes the function from the call stack and adds it to the settimeout API. Otherwise, the recursive function creates a stack overflow. What is actually going on under the hood?

const list = new Array(60000).join('1.1').split('.');

function removeItemsFromList() {
    var item = list.pop();

    if (item) {
      setTimeout(removeItemsFromList, 0);
    }
};

removeItemsFromList();

Solution

  • To answer your question which is :

    Does the set timeout web API have no memory limit?

    I would say from what I found searching around to help you is that you may run into the problem of memory limitations available to node with setTimeOut function.

    Read more about it here