Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak: App crashes when it load more than 300 WebP images #622

Closed
aibrahim3546 opened this issue Jan 17, 2020 · 10 comments
Closed

Memory leak: App crashes when it load more than 300 WebP images #622

aibrahim3546 opened this issue Jan 17, 2020 · 10 comments
Labels

Comments

@aibrahim3546
Copy link

Describe the bug
I am using a WebP image. the memory get so hight up to 1gb when i try to load more that 300 image. And end up crashing the app because of out of memory.

To Reproduce
Try to load more than 300 WebP images.

Expected behavior
Memory doesn't leak and wont crash the app. Are there anyway that i can clear the memory?

Dependency versions

  • React Native version: 0.61.4
  • React version: 16.9.0
  • React Native Fast Image version: 7.0.2
@dreampiggy
Copy link
Contributor

dreampiggy commented Jan 22, 2020

Upgrade the SDWebImageWebPCoder to v0.5.0 should fix this issue. See SDWebImage/SDWebImageWebPCoder#29

This is not a memory leak, but just the memory usage is high.

Almouro added a commit to Almouro/react-native-fast-image that referenced this issue Feb 6, 2020
This improves RAM usage for static webp assets (see SDWebImage/SDWebImageWebPCoder#30)

Potentially related to DylanVann#622
@klaaz0r
Copy link

klaaz0r commented Feb 23, 2020

@dreampiggy is this fixes in the latest version of NPM? I still get huge spikes in memory usages

@dreampiggy
Copy link
Contributor

dreampiggy commented Feb 24, 2020

@klaaz0r Doesn't this issue been fixed ?

In the 0.5.0 we optimize the Static WebP images, which does not cause double RAM usage. (previously it allocate the same size CGContext as pixel size, means 2x RAM usage. But CGContext is useless for Static WebP).

@dreampiggy
Copy link
Contributor

dreampiggy commented Feb 24, 2020

If you already use tons of WebP images and Animated WebP, maybe this 0.5.0 upgrade does not fix the issue from stratch (Only can help to reduce memory pressure). Because bitmap image always need RAM to allocate, this can not been avoid.

You can try to limit your image size, by changing the original image (let your image server provider to provide a smaller size). Or you can use the thumbnail decoding feature. See: Thumbnail Decoding.

But those feature only available in iOS native code, there are no React JavcScript bridge currently...

@klaaz0r
Copy link

klaaz0r commented Feb 24, 2020

@dreampiggy I think the problem I am having is caused by something else, I did some comparison and loading in a few hundred images inside a flatlist didn't result in any problems. Memory spikes occurred when image urls got a 404 (or any other non-200).
I made an issue here:
#635

@dreampiggy
Copy link
Contributor

dreampiggy commented Feb 24, 2020

@klaaz0r Can you provide a demo to show the 404 case that cause OOM ?

For iOS part of reat-native-fast-image (using SDWebImage), once a image url was returned 404, it will be blacked list (until you disbale this feature), next time this url will immediately fail. Even you disable black list, this does not cause Bitmap allocation which result so huge RAM usage.

I guess there are some leak in here.

@klaaz0r
Copy link

klaaz0r commented Feb 24, 2020

@dreampiggy I will create a repo with some examples showing what happens! If you want to quickly test it yourself you can try to add some dead links/link responding with text inside the examples

DylanVann pushed a commit that referenced this issue Mar 14, 2020
This improves RAM usage for static webp assets see:
SDWebImage/SDWebImageWebPCoder#30

Potentially related to #622
@dreampiggy
Copy link
Contributor

dreampiggy commented Apr 11, 2020

@aibrahim3546 @klaaz0r
Have a try with SDWebImage 5.7.2 + and SDWebImageWebPCoder 0.5+.

See changelog:

SDWebImage 5.7.2 version released. I think this solve some OOM issue for large number of images using in SDAnimatedImageView.

connoremma pushed a commit to gametimesf/react-native-fast-image that referenced this issue May 11, 2020
This improves RAM usage for static webp assets see:
SDWebImage/SDWebImageWebPCoder#30

Potentially related to DylanVann#622
@DylanVann
Copy link
Owner

Might be fixed by latest updates to SDWebImage (thanks @dreampiggy). Give it a shot. If not open a new issue. Thank you!

@Stafox
Copy link

Stafox commented Oct 24, 2020

Looks like the issue still exists. Created the new issue #738

alicayan008 pushed a commit to alicayan008/ReactNative-fast-image that referenced this issue Jul 4, 2023
This improves RAM usage for static webp assets see:
SDWebImage/SDWebImageWebPCoder#30

Potentially related to DylanVann/react-native-fast-image#622
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants