[Matter.framework] Clear all device controller delegates on controller shutdown (#35935)
diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm
index 013e892..5695ef2 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm
@@ -313,7 +313,7 @@
- (void)shutdown
{
- // Subclass hook; nothing to do.
+ [self _clearDeviceControllerDelegates];
}
- (nullable NSNumber *)controllerNodeID
@@ -671,6 +671,14 @@
}
}
+- (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 42ee83d..eb7881b 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
@@ -418,6 +418,7 @@
return;
}
[self finalShutdown];
+ [super shutdown];
}
- (void)finalShutdown