Deinit not called in certain scenarios with for await loop

FWIW I’ve also just been through this same process of coming to understand why my use of Tasks was completely broken and causing objects to not get released.

My use case is view models in an iOS app which use long-running tasks to track the state of dependencies, and my solution is to take advantage of SwiftUI’s .task lifecycle helper. This is a straightforward way to get all long-running tasks cancelled at a definite point in time, after which all references to the model are gone and it can be released after its view disappears. I gave some more thoughts here:

1 Like