Skip to content

Commit

Permalink
Added a log when we try to run a block but was deallocated, added the…
Browse files Browse the repository at this point in the history
… pendingblock to cancel in dealloc also
  • Loading branch information
mbruin-NR committed Feb 4, 2025
1 parent 55249d4 commit 6aca4e4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Agent/Analytics/PersistentEventStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ - (nonnull instancetype)initWithFilename:(NSString *)filename
return self;
}

- (void) dealloc {
if(self.pendingBlock){
dispatch_block_cancel(self.pendingBlock);
}
}

- (void)performWrite:(void (^)(void))writeBlock {
__weak PersistentEventStore *weakSelf = self;
dispatch_async(self.writeQueue, ^{
__strong PersistentEventStore *strongSelf = weakSelf;
if (!strongSelf) return; // Ensure strongSelf is not nil
if (!strongSelf) { // Ensure strongSelf is not nil
NRLOG_WARNING(@"A block was scheduled but PersistentEventStore was deallocated before running");
return;
}

if (strongSelf.pendingBlock != nil) {
dispatch_block_cancel(strongSelf.pendingBlock);
Expand Down

0 comments on commit 6aca4e4

Please sign in to comment.