I have a really simple SwiftUI view that is listing a bunch of Texts:
extension String: Identifiable {
public var id: String { return self }
}
struct ContentView: View {
var items: [String] = (0..<1000).map { $0.description }
var body: some View {
List(items) { str in
HStack {
Text(str)
}
}
}
}
This code seems to work fine and gives me smooth scroll performance.
If I change this so that the HStack is inside of a horizontally scrolling ScrollView:
var body: some View {
List(items) { str in
ScrollView(.horizontal) {
HStack {
Text(str)
}
}
}
}
There is an enormous performance hit and memory appears to grow unbounded as I scroll up and down through the list. There aren’t any leaks in the memory debugger.
I’m wondering if anyone knows why the performance hit is so massive and if there’s any way around it.
Update:
The HStack and Text appear to be irrelevant to the issue, even a Spacer inside the scrollView will trigger the issue.
List(items) { _ in
ScrollView(.horizontal) {
Spacer()
}
}
It seems like there might be a memory leak issue with at least List, ScrollView, Form, and NavigationView (see this question). The author of that question filed feedback with Apple (FB7318839). I would encourage you to do so as well, and hopefully it's just a bug that gets fixed soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With