Web Worker consumes massive amount of memory Web Worker consumes massive amount of memory multithreading multithreading

Web Worker consumes massive amount of memory


I found that if I run the garbage collector manually from developer tools -> Timeline it clears out all of the memory. Similarly, if I begin interacting with the Worker context from the console, calling functions seems to randomly trigger successful gc.

Based on this, I would say that there is not a hanging reference, but that receiving objects via a transfer may not force a gc check as new allocation requests would.

Transferring the object back with a response seems to workaround the problem:

postMessage('hi', [ev.data]);  // process usage stays around 50MB

As an alternative, making sure the Worker is non-trivial and will need to do normal allocations also seems to properly trigger gc, i.e:

  postMessage('hi');  var twoMB = new ArrayBuffer(8388608); // usage cycles 70MB - ~220MB