I know I'm (too!) late to the party, but I had cause to look deeper into this recently and I realized a couple things:
- As discussed in the ProgressReporter thread, the current implementation has a shortcoming where if
withObservationTrackingdiscovers that theemitclosure observes no properties (and will therefore never be run again) the sequence does not finish. - As discussed in the ProgressReporter thread,
withObservationTrackinginherently creates a window where concurrent changes are not tracked. Observation really wants to be able to guarantee thatObservabletypes are either global-actor-isolated or non-Sendable, which the type system can't represent. withObservationTrackingdoesn't provide an option to cancel an established observation. This sequence actually mitigates this somewhat because you can cancel the iterating task, but it's still the case that a long-lived object which many people begin observing, but which never changes, leaks memory through an ever-increasing set ofobservationsandlookups.
I don't see how to avoid the latter two issues without a replacement for withObservationTracking that creates a persistent observation (avoiding windows where concurrent mutations aren't tracked), and allows that observation to be explicitly cancelled (freeing up its resources on the observed objects).