Using Chrome, launch Task Manager (Shift+ESC), click the worker invert button a few times, each time it goes up ~10 MB. Anytime I receive a message back from the worker the memory goes up, it's not from modifying or accessing the canvas, it happens when the worker sends the message back to the main thread. It gets worse the larger the message is.
Adding the ImageData buffer to the optional transferables list on postMessage doesn't make a difference, same result, I'm wondering if there's another way I should approach this.
imageData = ctx.getImageData(0, 0, 800, 600);
You dont have a memory leak. This is just normal GC behaviour and there is not much you can do to stop the seemingly excessive memory use.
I had a play with your fiddle changing the code so that the
worker.onmessage function immediately called
startWork, effectively putting it in a loop, send the data, receive the inverted data set, put it on the canvas, then call
startWork again and let it go while I had a coffee. It ran just fine.