Posts

Post not yet marked as solved
1 Replies
348 Views
Hi to everyone I am developing a photo utility app in SwiftUI. But there is something I don't understand about Image View's memory management. In my attempts it seems that when an image is created in SwiftUI it will never be destroyed (never deallocated in memory) I tried this simple test view which shows one image at a time taken from a set of images loaded from the main bundle (Assets.xcassets). This is the code: struct ImageTest: View {       @State var index = 1   var imageName : String { "Image\(index)"}       var body: some View {     VStack {       Image(imageName)         .resizable()         .aspectRatio(contentMode: .fit)       Spacer()       Button(action:{ index += 1 }) { Text("Next") }     }   } } I thought that every time the "Next" button was clicked, a new image was created. Then the old one was destroyed. But it seems that this is not the case. When I run the app I see the memory grow every time I press the button and the new image appears. Memory is never released. I do not understand. I hope someone can help me Thank you
Posted Last updated
.