Probably memory will be allocated when you set the width/height properties, deallocated when you set them to 0.
If this is true, we'll use the same amount of memory as before.
Yeah; if the old canvases are garbage-collected right away after the
ImageData no longer holds a reference to them, then this patch won't save us memory. Intuitively it seems like reusing contexts will reduce the potential for leaking canvases and contexts, but I don't know how much of an issue this is in practice.
About perf, do you think using the same canvas and setting its width/height is going to be faster than creating new canvases?
It'll definitely create less work for the garbage collector, and we get to avoid function calls in the
ImageDataFactory methods, but this PR also converts some
ImageData methods to hand-written JS, which I'm told is slower than compiled Java. With the patch applied there's no noticeable performance difference so I'll have to profile to determine whether perf has been meaningfully affected