Originally brought up in https://codereview.chromium.org/2386453003#msg148.
Prior to https://codereview.chromium.org/2618633004/ (add support for APNG), PNGImageDecoder called createInterlaceBuffer (a block of memory used for updating rows of interlaced PNGs prior to transferring to the ImageFrame, possibly premultiplying in the transfer) when the first row was received, and then deleted the PNGImageReader (thus freeing the memory for the interlace buffer) when the image was complete.
With the switch to APNG, we still create the interlace buffer when we receive the first row, and we delete it (but not the PNGImageReader) when the frame is complete.
We could be more efficient (less allocations and frees) by reusing the interlace buffer from frame to frame. If we never delete it (i.e. wait until the PNGImageDecoder is deleted), each time we need to decode (or redecode) a frame the interlace buffer will be available to use, but it also means when we do not need it (e.g. image is not animating, decoded frame is already in m_frameBufferCache), we are paying the cost of holding that extra allocation in memory.
One compromise between memory and speed would be to reuse the buffer inside a call to PNGImageDecoder::decode[1]. If we have to decode more than one frame in one call, the buffer would be reused for all of them.
[1] https://chromium.googlesource.com/chromium/src/+/8fc913/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.cpp#69