I am noticing that in both Google Chrome and Microsoft Edge the Worker objects are not garbage collected. After running the following standalone simple test case, doing memory profile and checking for Worker class shows all the worker objects as retained.
<html>
<body>
<div id="app"></div>
<script>
const js = 'var array = new Array(1024*1024).fill("Hello world")';
const blob = new Blob([js], { type: 'application/javascript' });
const wurl = URL.createObjectURL(blob);
for(let i=1;i<=100;i++) {
const w = new Worker(wurl);
const result = { id: i };
document.getElementById('app').innerHTML = JSON.stringify(result);
w.terminate();
}
</script>
</body>
</html>
How to ensure the worker objects are freed?