Skip to content

Instantly share code, notes, and snippets.

@VAndrJ
Created January 14, 2025 15:38
Show Gist options
  • Save VAndrJ/d64a6680425d88b767c5175a8958b5a1 to your computer and use it in GitHub Desktop.
Save VAndrJ/d64a6680425d88b767c5175a8958b5a1 to your computer and use it in GitHub Desktop.
.searchable + .refreshable with ScrollView memory leak issue iOS 17.3+
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
NavigationLink("Next") {
TestView()
}
}
}
}
struct TestView: View {
@StateObject var vm2 = ObservableObjectViewModel()
@State var array = Array(1...2_000_000)
@State var text = ""
let num = 10
var body: some View {
ScrollView {
LazyVStack {
ForEach(0...10, id: \.self) {
Text("\($0)")
}
}
}
.refreshable {
print(num)
}
.searchable(text: $text)
}
}
class ObservableObjectViewModel: ObservableObject {
let id = UUID()
let array = Array(1...2_000_000)
init() {
print(#function, Self.self, id)
}
deinit {
print(#function, Self.self, id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment