@@ -757,7 +757,9 @@ - (void)_ensureSubscriptionForExistingDelegates:(NSString *)reason
757
757
}
758
758
if ([self _deviceUsesThread ]) {
759
759
MTR_LOG (" => %@ - device is a thread device, scheduling in pool" , self);
760
+ mtr_weakify (self);
760
761
[self _scheduleSubscriptionPoolWork: ^{
762
+ mtr_strongify (self);
761
763
[self ->_deviceController asyncDispatchToMatterQueue: ^{
762
764
std::lock_guard lock (self->_lock );
763
765
[self _setupSubscriptionWithReason: [NSString stringWithFormat: @" %@ and scheduled subscription is happening" , reason]];
@@ -1165,10 +1167,13 @@ - (void)_scheduleSubscriptionPoolWork:(dispatch_block_t)workBlock inNanoseconds:
1165
1167
return ;
1166
1168
}
1167
1169
1170
+ mtr_weakify (self);
1168
1171
dispatch_block_t workBlockToQueue = ^{
1172
+ mtr_strongify (self);
1169
1173
// In the case where a resubscription triggering event happened and already established, running the work block should result in a no-op
1170
1174
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc ] initWithQueue: self .queue];
1171
1175
[workItem setReadyHandler: ^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {
1176
+ mtr_strongify (self);
1172
1177
MTR_LOG (" %@ - work item is ready to attempt pooled subscription" , self);
1173
1178
os_unfair_lock_lock (&self->_lock );
1174
1179
#ifdef DEBUG
@@ -1246,7 +1251,9 @@ - (void)_handleResubscriptionNeededWithDelayOnDeviceQueue:(NSNumber *)resubscrip
1246
1251
1247
1252
// Use the existing _triggerResubscribeWithReason mechanism, which does the right checks when
1248
1253
// this block is run -- if other triggering events had happened, this would become a no-op.
1254
+ mtr_weakify (self);
1249
1255
auto resubscriptionBlock = ^{
1256
+ mtr_strongify (self);
1250
1257
[self ->_deviceController asyncDispatchToMatterQueue: ^{
1251
1258
[self _triggerResubscribeWithReason: @" ResubscriptionNeeded timer fired" nodeLikelyReachable: NO ];
1252
1259
} errorHandler: ^(NSError * _Nonnull error) {
@@ -1357,7 +1364,9 @@ - (void)_doHandleSubscriptionReset:(NSNumber * _Nullable)retryDelay
1357
1364
1358
1365
// Call _reattemptSubscriptionNowIfNeededWithReason when timer fires - if subscription is
1359
1366
// in a better state at that time this will be a no-op.
1367
+ mtr_weakify (self);
1360
1368
auto resubscriptionBlock = ^{
1369
+ mtr_strongify (self);
1361
1370
[self ->_deviceController asyncDispatchToMatterQueue: ^{
1362
1371
std::lock_guard lock (self->_lock );
1363
1372
[self _reattemptSubscriptionNowIfNeededWithReason: @" got subscription reset" ];
0 commit comments