Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion library/objective-c/EnvoyNetworkMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ - (void)dealloc {
if (_path_monitor) {
nw_path_monitor_cancel(_path_monitor);
}
if (_reachability_ref) {
SCNetworkReachabilitySetCallback(_reachability_ref, nil, nil);
SCNetworkReachabilitySetDispatchQueue(_reachability_ref, nil);
CFRelease(_reachability_ref);
}
}

- (void)startPathMonitor {
Expand All @@ -38,6 +43,7 @@ - (void)startPathMonitor {
nw_path_monitor_set_queue(_path_monitor, queue);

__block envoy_network_t previousNetworkType = -1;
envoy_engine_t engineHandle = _engineHandle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was causing a retain cycle in the nw update block.

nw_path_monitor_set_update_handler(_path_monitor, ^(nw_path_t _Nonnull path) {
BOOL isSatisfied = nw_path_get_status(path) == nw_path_status_satisfied;
if (!isSatisfied) {
Expand All @@ -60,7 +66,7 @@ - (void)startPathMonitor {

if (network != previousNetworkType) {
NSLog(@"[Envoy] setting preferred network to %d", network);
set_preferred_network(_engineHandle, network);
set_preferred_network(engineHandle, network);
previousNetworkType = network;
}

Expand Down