Description
Hi,
I'm using SDWebImageWebPCoder
with react-native-fast-image
and I found that the memory usage is quite high. We use non-animated WebP images but it seems like RNFI uses SDAnimatedImageView to load the images. After profiling I found both _canvas
and imageRef
in safeAnimatedImageFrameAtIndex
are retained. Which makes sense I guess since the canvas is reused for the animation. However for images this causes unnecessary memory usage.
As a temporary workaround I altered animatedImageFrameAtIndex
so it releases the canvas after the final frame of the animation (which for an image is immediately)
- (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index {
UIImage *image;
if (index >= _frameCount) {
return nil;
}
SD_LOCK(_lock);
image = [self safeAnimatedImageFrameAtIndex:index];
SD_UNLOCK(_lock);
if (index + 1 >= _frameCount) {
CGContextRelease(_canvas);
_canvas = NULL;
}
return image;
}
I don't think this is a great workaround since it impacts the behavior for animated WebP images (but it may be unnecessary to keep two copies of the image in memory?) so I wondered if there is another way to reduce the memory usage of WebP in SDWebImage and possibly improve RNFI.