ImageDecoder::ClearCacheExceptFrame() has to keep an eligible previous reference frame if the current frame's disposal method is DisposePrevious. It needs a previous frame that it can use after being disposed.
The problem is after decoding frame i, we keep an eligible reference frame for frame i. Really, we need an eligible reference frame for i+1.
There is a chance that the eligible reference frame list is the same. But there is also a change that we save a frame that isn't an eligible reference frame for i+1.
Saving the wrong frame in cache would force us to re-decode possibly several frames to get an eligible reference frame.
What's more, the image decoders may have been provided enough data to parse frame i+1 and know in advance which frame should be saved. It is possible that this would be a free optimization.