LoginSignup
3
0

More than 5 years have passed since last update.

AndroidのFlatListでOutOfMemory

Last updated at Posted at 2017-10-10

問題

Androidでクラッシュ。
画像をたくさん読んでいるのでOutOfMemoryっぽい

ListViewはほぼほぼFlatListに置き換えているのに何でだろう

調べたこと

android manifestでlargeHeap = trueにする
https://stackoverflow.com/questions/39655791/out-of-memory-application-crash-react-native

下記の3つをやってみる

1.Make sure FlatList is not a child of ScrollView as scrollview will render all child components, even those not on the screen in FlatList.
2.Add prop removeClippedSubviews to FlastList so it removes items out of view. (didn't test if this is redundant to #1)
3.Implement shouldComponentUpdate for the renderItem component or make it a PureComponent.

やってみる

largeHeap = true

heapが大きくなるので画像が表示されない、みたいな問題はなくなるが、結局落ちるときには落ちる

scroll view と flatlistのネストをやめる

全体の構造を変えないと行けないのでスキップ

removeClippedSubviews

多少マシになった感あり。要検証。
※ bugもあるようなので自己責任でとのこと

shouldComponentUpdateを組み込む

後回し

その他

react-navigation使っているのですが、stack navigatorで重ねた時に下のscreenは残っているので、重いもの重なり過ぎている説は有力

結論

ロジックも含めて継続改善中。。
良い方法あれば教えてください、、 <-

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0