developit / workerize-loader

🏗️ Automatically move a module into a Web Worker (Webpack loader)
https://npm.im/workerize-loader
2.31k stars 86 forks source link

Memory leak / lack of GC on Android Chrome when using workerize-loader #116

Open heliohm opened 3 years ago

heliohm commented 3 years ago

Hi,

First of all - thank you for a fantastic library to make web workers usable for more complex things :)

Not sure this is the right place to ask, but would appreciate some advice if anyone have seen similar problems before.

I have a project setup where I am pushing 35 MB/sec (10fps 1280x720) from a webcam feed to a worker set up by workerize-loader to search for QR codes in the image data (using HTML5 canvas).

This seems to work fine most of the time - the worker heap grows quickly according to memory snapshots in Chrome DevTools but is garbage collected frequently enough for Chrome to handle. The exception here is Android Chrome.

Memory snapshots on Android / Chrome Devtools show worker heap is frequently GC'ed (varies from 1.3MB to >100MB and back to 1.3MB) but then "suddenly" is not anymore (>500MB heap) and Chrome crashes. Looking at chrome://tracing with an Android phone connected shows available memory dropping continuously until things crash - the memory freed from the worker heap during GC is not shown as available in chrome://tracing.

Is there anything with the promise/event mechanism between the main thread and the worker that could make things not being garbage collected? Or could this be simply a Chrome bug on Android? Do I have a bug on my side? ¯_(ツ)_/¯

Sample project (Gatsby and React for now, soon Preact): https://codesandbox.io/s/1di20

Relevant files are /src/components/qreader-zxing.js and /src/workers/zxing.worker.js