Tengo un problema con ArrayBuffer. No entiendo por qué la memoria no se libera. Tal vez alguien sepa cómo solucionarlo.
// Main thread const startLongTask = () => { setLoading(true); const worker = new Worker( new URL("../webworkers/matrix.js", import.meta.url) ); worker.onmessage = ({ data }) => { setLoading(false); console.log(data); worker.terminate(); }; const matrix = new Uint8Array(1000000000); worker.postMessage(matrix, [matrix.buffer]); }; // Worker thread onmessage = ({ data: matrix }) => { const matrixView = new DataView(matrix.buffer); for (let i = 0; i < matrix.byteLength; i++) { matrixView.setInt8(i, i >= 255 ? 255 : i); } postMessage(matrix, [matrix.buffer]); };Parece que hay una pérdida de memoria debido a console.log(data);
Con consola.log
https://monosnap.com/file/Qwbu7LRGWFaHptic1bG5YLsVGyKj7d
Sin consola.log