最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - high memory consumption in basic react-native app - Stack Overflow

programmeradmin2浏览0评论

I was making my first react native and as much easy I though it would be, it is turning out to be difficult for me to understand what I could be doing wrong.

To start with, I have a very simple app which fetches data through redux

ponentWillMount() {

    this.props.fetchCoin()
    this.props.CurrencyRate()
  }

and then renders this in its return part

 return (
     <ScrollView>
                 <Header />
                 {/* Custom Search Input */}
                 <View>
                 <TextInput
                  style={textInput}
                  placeholder="Search Coin"
                  onChangeText={(text) => this.onSearch(text)} />
                  </View>
                  <View>
                  <FlatList
                   data={this.state.searchCoin ? displaySearchCrypto : this.props.cryptoLoaded}
                   renderItem={({ item }) => (
                   <CoinCard
                      key={item["long"]}
                      coinShortName = {item["short"]}
                      coinName = {item["long"]}
                      coinPrice = {item["price"].toFixed(2)}
                      marketCap = {(item["mktcap"]/1000000000).toFixed(4)}
                      percentChange = {item["perc"].toFixed(2)}
                      vwapData={item["vwapData"].toFixed(2)}
                      coinImage={"/" + item["long"] + ".png"}
                      />
                  )}
          />
          </View>
               </ScrollView>
           )
      }
    }

I am seeing my ram consumption to be greater than 500 MB even after the app have fetched data and UI thread sticked to 60 (fps) where i think nothing in UI is happening

Instead of sharing all my code: You can find most of the stuff at github The above snippet code is shared from here: .js

The CoinCard Component in the above code can be seen here: .js

And Action for the same is here: .js

[Question:] Can someone please help me find out what am I doing wrong and how could I fix it? This repository should work on your simulator without throwing an error if in case someone wants try it out.

I was making my first react native and as much easy I though it would be, it is turning out to be difficult for me to understand what I could be doing wrong.

To start with, I have a very simple app which fetches data through redux

ponentWillMount() {

    this.props.fetchCoin()
    this.props.CurrencyRate()
  }

and then renders this in its return part

 return (
     <ScrollView>
                 <Header />
                 {/* Custom Search Input */}
                 <View>
                 <TextInput
                  style={textInput}
                  placeholder="Search Coin"
                  onChangeText={(text) => this.onSearch(text)} />
                  </View>
                  <View>
                  <FlatList
                   data={this.state.searchCoin ? displaySearchCrypto : this.props.cryptoLoaded}
                   renderItem={({ item }) => (
                   <CoinCard
                      key={item["long"]}
                      coinShortName = {item["short"]}
                      coinName = {item["long"]}
                      coinPrice = {item["price"].toFixed(2)}
                      marketCap = {(item["mktcap"]/1000000000).toFixed(4)}
                      percentChange = {item["perc"].toFixed(2)}
                      vwapData={item["vwapData"].toFixed(2)}
                      coinImage={"https://coincap.io/images/coins/" + item["long"] + ".png"}
                      />
                  )}
          />
          </View>
               </ScrollView>
           )
      }
    }

I am seeing my ram consumption to be greater than 500 MB even after the app have fetched data and UI thread sticked to 60 (fps) where i think nothing in UI is happening

Instead of sharing all my code: You can find most of the stuff at github The above snippet code is shared from here: https://github./irohitb/Crypto/blob/master/src/container/cryptoContainer.js

The CoinCard Component in the above code can be seen here: https://github./irohitb/Crypto/blob/master/src/ponents/CoinCard.js

And Action for the same is here: https://github./irohitb/Crypto/blob/master/src/actions/cryptoAction.js

[Question:] Can someone please help me find out what am I doing wrong and how could I fix it? This repository should work on your simulator without throwing an error if in case someone wants try it out.

Share Improve this question edited Sep 5, 2018 at 12:07 Hyyan Abo Fakher 3,5273 gold badges24 silver badges36 bronze badges asked Sep 5, 2018 at 11:43 AlwaysblueAlwaysblue 12k44 gold badges141 silver badges253 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

FlatList with Image has an open issue on Android: https://github./facebook/react-native/issues/13413. There are some tips on performance here: https://github./filipemerker/flatlist-performance-tips/

As a first attempt to fix, try adding removeClippedSubviews to your FlatList, although that es with trade offs.

I also note in the screenshot that you are getting a warning about missing keys. Fix that issue and try keyExtractor and see if that improves things.

Alternatively, use something other than FlatList, e.g. ScrollView. You will lose some of the features of the FlatList but if you get acceptable memory usage and performance, it may be worth it.

发布评论

评论列表(0)

  1. 暂无评论