Created
January 14, 2025 15:38
-
-
Save VAndrJ/d64a6680425d88b767c5175a8958b5a1 to your computer and use it in GitHub Desktop.
.searchable + .refreshable with ScrollView memory leak issue iOS 17.3+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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