vovkasm / react-native-web-image

An image component for react-native with persistent disk and memory caching.
MIT License
146 stars 25 forks source link

iOS app crashes on physical device #18

Open bvv218 opened 6 years ago

bvv218 commented 6 years ago

I am using web image for FlatList Items, and when I have many items (10+), ios app on physical device just crashes without any errors in the console. It works great on iOS simulator and android physical devices, but crashes on iOS physical devices. I tried replacing web image with image tag and it works as expected without crash.

vovkasm commented 6 years ago

Can you try run app from Xcode?

I can try to reproduce it, but can you please provide at least basic scheme of code with FlatList and versions of react-native-web-image, RN, ios and Xcode?

bvv218 commented 6 years ago

@vovkasm I tried running app from Xcode and app crashed again (Lost connection to iPhone error), but simulator still works as expected. iOS: 10.3.3, react-native-web-image: 0.0.6, react: 16, react-native: 0.51.0, Xcode: 9.

Sample code (inside React.PureComponent):

<FlatList
        removeClippedSubviews={true}
        data={this.state.data}
        renderItem={({item}) => {
            return (
        <View style={styles.container}>
         <WebImage
              resizeMode={'cover'}
                    style={styles.image }
                    source={{
                      uri: item.image 
                    }}
                  />
        </View>
          );
          }}
         keyExtractor={(item, index) => index}
        />
vovkasm commented 6 years ago

Thanks! Very strange crash, before I will chance to look at this in details, can you test with develop branch, it uses newer version of SDWebImage?

bvv218 commented 6 years ago

@vovkasm I tried to install develop version, but I receive this error: Showing Recent Issues clang: error: linker command failed with exit code 1 (use -v to see invocation) ... was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build file

vovkasm commented 6 years ago

Oops... sorry, I tried to hide SDWebImage symbols, by linker black magic, seems this caused bitcode issues... ( Will revert this commits soon

vovkasm commented 6 years ago

@bvv218 just reverted it, sorry again (

bvv218 commented 6 years ago

@vovkasm Thanks, I will try it again right now. Can the crash be possibly caused by the memory usage? I noticed that when I use memory usage is between 90-115MB no matter how many pictures I have, but when I use web-image and scroll down couple of picture, it shoots up to 300MB and after that app crashes. Not sure if that's the real cause.

bvv218 commented 6 years ago

@vovkasm The app crashes with develop version install as well.

vovkasm commented 6 years ago

@bvv218 Well, I will try to replicate the crash with FlatList and see what happens. Yes, it is probably a memory issue, but usually this does not happen silently. System logs (can be seen in Console.app on latest macos versions) usually contain some info.

One question: How big are the images which your app loads?

bvv218 commented 6 years ago

@vovkasm I don't see any logs after the crash. Images are on average 3MB each.

vovkasm commented 6 years ago

Can confirm crash (ios, real device). Yes it is memory issue. Thank you for finding this!

I added two samples using flat list, they can be seen in samples/SampleApp on develop branch. First loads NASA image set, it not crashes (images sizes about 200Kb)... Second loads generated images 7MB each, it renders FlatList with 200 items. It crashes on real device. ((

Will try to investigate deeper, but it needs some time... :-/

Random facts:

  1. SDWebImage has various options especially for big image handling, but this options currently not exposed to JS.
  2. Above options still may not solve problem. Seems like behavior of FlatList leads to very dense memory pressure in very small time intervals... Seems like original RN Image loader somehow can work in sync with such "impulses" and spreads own processes like image decoding, rescaling etc...
  3. According to instruments, almost all memory allocated from SDWebImage decoder components, but this requires further research.

Anyway I will glad to any help with any ideas/resources/code that can help with this problem.