Skip to content

Commit 6aca4e4

Browse files
committed
Added a log when we try to run a block but was deallocated, added the pendingblock to cancel in dealloc also
1 parent 55249d4 commit 6aca4e4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Agent/Analytics/PersistentEventStore.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@ - (nonnull instancetype)initWithFilename:(NSString *)filename
4040
return self;
4141
}
4242

43+
- (void) dealloc {
44+
if(self.pendingBlock){
45+
dispatch_block_cancel(self.pendingBlock);
46+
}
47+
}
48+
4349
- (void)performWrite:(void (^)(void))writeBlock {
4450
__weak PersistentEventStore *weakSelf = self;
4551
dispatch_async(self.writeQueue, ^{
4652
__strong PersistentEventStore *strongSelf = weakSelf;
47-
if (!strongSelf) return; // Ensure strongSelf is not nil
53+
if (!strongSelf) { // Ensure strongSelf is not nil
54+
NRLOG_WARNING(@"A block was scheduled but PersistentEventStore was deallocated before running");
55+
return;
56+
}
4857

4958
if (strongSelf.pendingBlock != nil) {
5059
dispatch_block_cancel(strongSelf.pendingBlock);

0 commit comments

Comments
 (0)