Fiddle: https://jsfiddle.net/eimmot/065wxa9o/9/
Using Chrome, start the task manager (Shift + ESC), press the workflow inversion button several times, each time it rises ~ 10 MB. At any time, when I receive a message from a worker, the memory rises, it is not from changing or accessing the canvas, this happens when the worker sends the message back to the main thread. It gets worse the bigger the message.
Adding the ImageData buffer to the optional portable list in postMessage does not matter, the same result, I wonder if there is another way that I should approach this.
imageData = ctx.getImageData(0, 0, 800, 600);
worker.postMessage(imageData, [imageData.data.buffer]);
However, it does not matter if the main thread and / or the worker thread are transmitted. I see on the console that the imageData object is actually transferring ownership, but memory is still expanding! I tried memory profiling with the chrome dev tools, but I don't see where this increase is.
Forcing the GC in dev tools clears memory. Sometimes the GC starts automatically, sometimes it’s not, when it does, it releases only 10% of what has been allocated.
I read many pages last night, but they all say the same thing, and it seems to me that I'm missing something simple.
Portable Objects: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#Passing_data_by_transferring_ownership_(transferable_objects)
Update
Chrome version 48.0.2564.116 beta-m (64-bit)
Fiddle: https://jsfiddle.net/eimmot/065wxa9o/13/
, , - , , ,