grpc-swift icon indicating copy to clipboard operation
grpc-swift copied to clipboard

ConnectivityStateDelegate should be weak

Open dannyhertz opened this issue 3 years ago • 1 comments

Describe the bug

The delegate property of the ConnectivityStateMonitor should be weak and is currently causing values to be retained longer than necessary because of it.

https://github.com/grpc/grpc-swift/blob/988ee3fcc98598c39db8385e92d1c8bb4e3c28a7/Sources/GRPC/ConnectivityState.swift#L76

To reproduce

Steps to reproduce the bug you've found:

  1. Create a channel and add a connectivity delegate via withConnectivityStateDelegate method
  2. Nil out the owner of the channel and observe that it is still in memory after being torn down.

Expected behaviour

Owner of channel (and delegate of connectivity monitor) should be torn down when the owner is torn down.

dannyhertz avatar Mar 17 '22 19:03 dannyhertz

grpc-swift uses an explicit shutdown mechanism: it does not shut its resources down on deinit. This is an intentional design pattern: you must close your channel explicitly.

Lukasa avatar Mar 18 '22 07:03 Lukasa