Skip to content

Commit

Permalink
Clear ivar after scheduling for main thread deallocation #trivial (#590)
Browse files Browse the repository at this point in the history
* Clear ivar after scheduling for main thread deallocation

After scheduling the ivar for main thread deallocation we have clear out the ivar, otherwise we can run into a race condition where the main queue is drained earlier than this node is deallocated and the ivar is still deallocated on a background thread

* First clear and than schedule
  • Loading branch information
maicki committed Sep 27, 2017
1 parent 6c00897 commit a103bab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,18 @@ - (void)_scheduleIvarsForMainDeallocation

for (Ivar ivar : ivars) {
id value = object_getIvar(self, ivar);
if (value == nil) {
continue;
}

if (ASClassRequiresMainThreadDeallocation(object_getClass(value))) {
as_log_debug(ASMainThreadDeallocationLog(), "%@: Trampolining ivar '%s' value %@ for main deallocation.", self, ivar_getName(ivar), value);

// Before scheduling the ivar for main thread deallocation we have clear out the ivar, otherwise we can run
// into a race condition where the main queue is drained earlier than this node is deallocated and the ivar
// is still deallocated on a background thread
object_setIvar(self, ivar, nil);

ASPerformMainThreadDeallocation(value);
} else {
as_log_debug(ASMainThreadDeallocationLog(), "%@: Not trampolining ivar '%s' value %@.", self, ivar_getName(ivar), value);
Expand Down

0 comments on commit a103bab

Please sign in to comment.