memory - matchGeometryEffect 对 ScrollView 内存泄漏的影响
问题描述
我使用 LazyVGrid 来显示文章库。一切正常,我没有内存警告,因为每次视图离开屏幕时,内存使用量都会减少。
我的问题是当我对图像使用matchedGeometryEffect时,以便将动画与新视图同步。
动画效果很好,但是在滚动视图滚动时内存正在增加。就像matchedGeometryEffect正在维护对对象的内存引用,并且不允许释放。
容器
LazyVGrid(
columns: [
GridItem(.flexible())
],spacing: 16
){
ForEach(viewModel.articles){ article in
LazyVStack{
ArticleCardView(article: article, animation: animation, show: $show)
.onTapGesture {
withAnimation(.spring()){
selectedArticle = article
show.toggle()
}
}
}
}
}
卡片视图
VStack{
if !show {
Image(uiImage: readImage(name: "\(article.id)00"))
.resizable()
.aspectRatio(contentMode: .fit)
//.matchedGeometryEffect(id: "img\(article.id)00", in: animation)
...
新观点
VStack{
GeometryReader { geo in
TabView {
Image(uiImage: readImage(name: "\(article!.id)00"))
.resizable()
.aspectRatio(contentMode: .fit)
//.matchedGeometryEffect(id: "img\(article!.id)00", in: animation, isSource: false)
.tag(1)
...
一切都很完美,但是如果我取消注释注释行,滚动时内存使用量会增加。
任何想法?比你
解决方案
已解决:我只是将视图嵌入到 VStack 并释放内存:
...
ForEach(viewModel.articles){ article in
VStack{
ArticleCardView(article: article, animation: animation, show: $show)...
推荐阅读
- php - IONOS 上的 htaccess 动态重定向问题
- nginx - 我们从 nginx 收到“18446744073709551615”响应,而不是正确的响应代码
- javascript - 基于计时器类,警告:在现有状态转换期间无法更新(例如在 `render` 中)
- c++ - 对头文件中的类成员函数和变量进行升序排序
- python - OSError [Errno -9988] 流在 Python 中关闭
- c# - 在单例中实例化预制件不起作用,即对象未实例化
- android - 如何将数据从广播接收器传递到回收器视图项
- sql - 在grafana中找到当前时间和上次失败之间的差异?
- db2 - 表创建过程 DB2
- c# - 如何修复这些 Unity 错误?