SDWebImageWebPCoder: High memory usage in RNFI
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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (7 by maintainers)
Maybe enough. I’ll have a check in 1 day. Thanks for your reply.
@dreampiggy I updated to SDWebImage 5.4.2, it works great. Again, thanks for your quick response 😃