Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear ivar after scheduling for main thread deallocation #trivial #590

Merged
merged 2 commits into from
Sep 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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