diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index a1872c302081bf..7374d6417894b2 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -800,6 +800,14 @@ - (void)removeDeviceControllerDelegate:(id)delegate } } +- (void)clearDeviceControllerDelegates +{ + @synchronized(self) { + _strongDelegateForSetDelegateAPI = nil; + [_delegates removeAllObjects]; + } +} + // Iterates the delegates, and remove delegate info objects if the delegate object has dealloc'ed // Returns number of delegates called - (NSUInteger)_iterateDelegateInfoWithBlock:(void (^_Nullable)(MTRDeviceControllerDelegateInfo * delegateInfo))block diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm index cb86c5d2db044f..c7429b91140dcc 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm @@ -450,6 +450,7 @@ - (void)cleanupAfterStartup [device invalidate]; } [self stopBrowseForCommissionables]; + [self clearDeviceControllerDelegates]; [_factory controllerShuttingDown:self]; } diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h b/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h index 958e7914b1dd3a..18d972c29de65a 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h @@ -237,6 +237,11 @@ NS_ASSUME_NONNULL_BEGIN - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(nullable NSDictionary *)prefetchedClusterData; - (void)removeDevice:(MTRDevice *)device; +/** + * Clear all delegates from the device controller + */ +- (void)clearDeviceControllerDelegates; + @end /**