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

<Image> take up a lot memory on Android #17801

Closed
1c7 opened this issue Jan 31, 2018 · 17 comments
Closed

<Image> take up a lot memory on Android #17801

1c7 opened this issue Jan 31, 2018 · 17 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@1c7
Copy link

1c7 commented Jan 31, 2018

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
  OS: macOS High Sierra 10.13.2
  Node: 8.9.4
  Yarn: 1.3.2
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: 16.0.0 => 16.0.0
  react-native: 0.51.0 => 0.51.0

image

Steps to Reproduce

  1. build a button that allow user to chose multiple image
    (I am using react-native-image-crop-picker for Android
  2. display these image in a <FlatList>
  3. select >20 image can cause App take 400~600MB memory.
  4. app could crash, depending on if the phone is high-spec or low-spec, cheap phone are more likely to crash since it has less memory

Expected Behavior

it doesn't take that much memory and cause app crash.

Actual Behavior

take about 400mb to 600mb memory. then my app crash

Reproducible Demo

image
369MB memory and keep growing to 400+mb
image

image

Thanks for reading 😄

@1c7
Copy link
Author

1c7 commented Jan 31, 2018

I am writing a demo for this, would post link here soon.
and also make a video with that demo.

@1c7
Copy link
Author

1c7 commented Jan 31, 2018

Demo App (React Native 0.52) with react-native run-android

https://github.com/1c7/react-native-image-memory-problem-demo-app

easily reproduce the problem. hope it help.

@gedeagas
Copy link
Contributor

This is an interesting bug, will try to reproduce the issue.

@1c7
Copy link
Author

1c7 commented Jan 31, 2018

@gedeagas Thanks!

@1c7
Copy link
Author

1c7 commented Jan 31, 2018

demo app video is done:

https://youtu.be/Vgq-P826aqw

@aknad
Copy link

aknad commented Feb 1, 2018

to reduce the memory usage you can try to add removeClippedSubviews={true} to your FlatList
then you should find a workaround for this old issue: #1831 / #368
we add a +1 scroll on componentWillReceiveProps

@1c7
Copy link
Author

1c7 commented Feb 1, 2018

@aknad Thanks! would try.

@1c7
Copy link
Author

1c7 commented Feb 7, 2018

I hope someone can take a look into this issue fast,
display image in a list is quite a common scenario.

@1c7
Copy link
Author

1c7 commented Feb 7, 2018

btw,
I have a old app(React Native 0.46) using ListView and loading image from Network.
it display a lot image, that list have like 300 item, but it work just fine. everything is smooth.

not sure this high memory problem is with FlatList?
or just display local image/network image are different,
somehow display local image is more difficult? need more work on downsampling or something?

if want try the old app I mention above, you can download here: https://www.coolapk.com/apk/com.crashcourse.china.c17

it's not on Google Play Store.
and also this is not an advertisement for my app,
I am just trying to provide more info to help diagnose this problem.

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 24, 2018
@1c7
Copy link
Author

1c7 commented Feb 24, 2018

I don't have time to retest this in 0.53.

@mattmcdonald-uk
Copy link

mattmcdonald-uk commented Mar 1, 2018

I can confirm this is an issue in 0.53.

Using removeClippedSubviews does mitigate the problem, but this isn't necessary on iOS as loading large lists of images doesn't grow memory usage in the same way.

@1c7
Copy link
Author

1c7 commented Mar 1, 2018

@mattmcdonald-uk so in 0.53, iOS doesn't have this problem, but Android still does?

@mattmcdonald-uk
Copy link

@1c7 Exactly

@mattmcdonald-uk
Copy link

@react-native-bot reopen

@facebook-github-bot
Copy link
Contributor

Something went wrong executing that command, @hramos could you take a look?

@kelset
Copy link
Contributor

kelset commented Mar 1, 2018

@mattmcdonald-uk please refer to #13413, so that we avoid redundancy - the core team is aware of this Android+Flat/SectionList+Images issue (going to write a follow up there).

@facebook facebook locked as resolved and limited conversation to collaborators Feb 24, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants