Alf*_*o G 5 memory-leaks memory-management ios swift swiftui
我正在使用使用UIPageViewController行为的选项卡视图。所以我定义了以下模型:
class WalktroughModel: Identifiable, ObservableObject {
let id: UUID = UUID()
let imageName: String
let title: String
init(imageName: String, title: String) {
self.imageName = imageName
self.title = title
}
}
Run Code Online (Sandbox Code Playgroud)
现在我使用这个 swiftUI 视图作为选项卡视图的子视图:
struct WalktroughAsset: View {
@StateObject var asset: WalktroughModel
var body: some View {
Image(asset.imageName)
.resizable()
.overlay(Color.black.opacity(0.43))
.overlay(
VStack{
Spacer()
Text(asset.title)
.foregroundColor(.white)
.font(.custom("OpenSans-regular", size: 22.0))
}
.padding(.bottom, 64)
)
}
}
Run Code Online (Sandbox Code Playgroud)
在我的内容视图中,我有以下内容:
struct ContentView: View {
var thumbs: [WalktroughModel] = [WalktroughModel(imageName: "splash-1", title: "Concepto 1"), WalktroughModel(imageName: "splash-2", title: "Concepto 2"), WalktroughModel(imageName: "splash-3", title: "Concepto 3")]
var body: some View {
ZStack {
Color.black.overlay(TabView{
ForEach(thumbs) {
image in
WalktroughAsset(asset: image)
}
}
.tabViewStyle(PageTabViewStyle())
.padding([.bottom, .top], 32)
)
}
.edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我构建和运行时,当我滑动到另一个视图时,内存会从 80 mb 跳到 160 mb,当我滑动到第三个视图时会跳到 230 mb。会发生什么?
此致
| 归档时间: |
|
| 查看次数: |
394 次 |
| 最近记录: |