diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerXPCConnection.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerXPCConnection.mm index e44308244cc00f..02f1e2c0ac134b 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerXPCConnection.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerXPCConnection.mm @@ -170,9 +170,12 @@ - (void)deregisterReportHandlersWithController:(id)controller [handle.proxy stopReportsWithController:controller nodeId:nodeID.unsignedLongLongValue completion:^{ + // Make sure handle stays alive until we get to this + // completion (in particular while we are working + // with handle.proxy). __auto_type handleRetainer = handle; (void) handleRetainer; - clearRegistry(); + dispatch_async(queue, clearRegistry); }]; } else { MTR_LOG_ERROR("CHIP XPC connection failed to stop reporting");