Thursday, 27 August 2020

Memory leak in TabView with PageTabViewStyle

I'm using a tab view using the UIPageViewController behaviour. So I defined the following model:

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
  }
}

Now I use this swiftUI view as a child view of tab view:

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)
          )
    }
}

In my content view I have the following:

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@*/)
    
   }
}

Now, when I build and run the memory jumps 80 mb to 160 mb when I swipe to the other view and jumps to 230 mb when I swipe to the third view. What could be happen?

Best Regards



from Memory leak in TabView with PageTabViewStyle

No comments:

Post a Comment