HarmonyOS Swiper是否不销毁不可见的item

Swiper使用默认的缓存页面 个数,但是我发现item页面无论滑到第几个或者都不可见了,都不会走aboutToDisappear()方法,是否都不会销毁不可见的 itemView,这样不会造成内存溢出吗?

Swiper(this.swiperController) {
  ForEach(this.wordList, (itemBeanStr: WordList, index: number) => {
    WordCardItem({
      palyAudio: this.playAudio,
      pageIndex: index,
      itemBean: itemBeanStr,
      bookType: this.bookType,
      audioPlaying: this.audioPlaying,
      selectedPage: this.selectedIndex - 1
    })
  }, (itemBeanStr: WordList, index: number) => index + "")
}.index(this.selectedPage).indicator(false).width('100%').alignRules({
  top: { anchor: 'tv_page', align: VerticalAlign.Bottom },
  bottom: { anchor: '__container__', align: VerticalAlign.Bottom }
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
HarmonyOS
2024-12-25 12:40:22
512浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

推荐使用lazyForEach来代替foreach,lazyforeach会根据滚动容器可视区域按需创建组件,对划出可视范围的组件会进行销毁,具体使用参考文档链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-rendering-control-lazyforeach-V5

分享
微博
QQ
微信
回复
2024-12-25 15:44:49


相关问题
UIAbility如何设置不可见
2605浏览 • 1回复 待解决
HarmonyOS Swiper里面的item高度自动刷新
985浏览 • 1回复 待解决
worker主动销毁会造成内存泄露吗
2795浏览 • 0回复 待解决
HarmonyOS 组件是否销毁回调方法
1488浏览 • 1回复 待解决
JS swiper 怎么像list一样动态添加item
7131浏览 • 1回复 待解决
Swiper数量是否有限制
2922浏览 • 1回复 待解决