I’m working on an in-house reactive programming framework. Framework heavily relies on comparing inputs to decide if something should be recomputed or update propagation can stop.
And data that users feed into the framework may contain pretty much anything including weak references and closures. To facilitate framework usage we ship a collection of property wrappers that help compiler synthesize equality conformance for user types.
False positives in equality lead to bugs - if I were using ObjectIdentifier
as a comparison key, there is a small chance that old object (some sort of delegate) would be destroyed, new one would be created at the same address, but framework would never propagate a reference to the new one.
False negatives lead to redundant updates - negativity affecting performance, but preserving correct behavior.
I think for most of the user use cases weak references don’t outlive the referent, up to some unaccounted dispatch_async
. So typically weak
is used instead of unowned
as a defensive measure.