Post

Replies

Boosts

Views

Activity

Reply to @Observable/@State memory leak
This issue sadly generally affects instances of reference types stored as @State, even without using the new Observation API. It can therefore be considered an iOS 17 regression since storing simple reference types as @State without @ObservableObject was possible without leaks on iOS 16 (I can also confirm that the issue does not arise with @ObservableObject conformance). Though in general you likely want automatic observation, sometimes being able to store an instance of a non-observable reference type for the lifetime of a SwiftUI view is still useful and legitimate. This is for example how you might store an AVPlayer displaying its content in a VideoPlayer view, as show in this official code sample. I also reported this issue as FB13126425. Sample code is available here.
Sep ’23