Skip to content

[WatchConnectivity] WatchConnectivitySession holds its delegate strongly — retain cycle with observers #87

@leogdion

Description

@leogdion

Bug

WatchConnectivitySession.storedDelegate (WatchConnectivitySession.swift, the NSLock-guarded backing store behind the delegate property) is a strong reference. Delegate patterns conventionally hold weak references; here, any observer that owns the session and registers itself as delegate forms a cycle:

observer → session (strong let) → storedDelegate (strong) → observer

Concretely, SundialKitStream's ConnectivityObserver does exactly this in its initializer, making the observer un-deinit-able (companion issue: brightdigit/SundialKitStream#17). The existing #warning("replace with a property wrapper or internal actor") on the lock is adjacent tech debt in the same property.

Fix direction

Store the delegate weakly (weak var storedDelegate: (any ConnectivitySessionDelegate & AnyObject)? — the protocol already requires AnyObject? if not, constrain it), keeping the lock or replacing it per the existing #warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcomponent:watchconnectivitySundialKitConnectivity implementation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions