Long-term solution for accidental retain cycles from strong references in closures

I’m not certain what the solution could entail, but for me too, retain cycles due to self-capturing closures (that are in turn being kept alive by self) is one of the hardest problems in Swift.

Our app receives realtime updates to values from a remote database.
This is currently modeled with subscriptions in RxSwift, but the issue is of course also present with Combine - or even with iteration over async streams using for await.

One thing that improves our situation is using the Observable macro together with view models for any ‘signal’ that only updates UI.

But not everything fits into that bucket and our app will continue to have a lot of code where we need to react to signals of changing values, which precisely has the shape where it’s way to introduce retain cycles.

My best hope is some kind of static analysis that could spot the cycles in the code, but I don’t know if such a thing could be possible.