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

Fix leak of weak references #323

Merged
merged 3 commits into from
Dec 21, 2024
Merged

Fix leak of weak references #323

merged 3 commits into from
Dec 21, 2024

Conversation

rfm
Copy link
Contributor

@rfm rfm commented Dec 20, 2024

In the case where an object has been deallocated, fetching the old value of a weak reference to it returns nil. If we are assigning nil to the weak reference we can't abort processing early (when we check that old and new values are the same) as that will leave the weak reference in place when the calling code thinks it has destroyed it.

In the case where an object has been deallocated, fetching the old value of a weak reference to it returns nil.  If we are assigning nil to the weak reference we can't abort processing early (when we check that old and new values are the same) as that will leave the weak reference in place when the calling code thinks it has destroyed it.
arc.mm Outdated
if (old == obj)
// If the old and new values are the same, then we don't need to do anything
// unless we are deleting the weak reference by storing NULL to it.
if (old == obj && (obj != NULL || NULL == oldRef))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add some brackets around this? I am not sure what the precedenc e is between || and == without looking it up and the next person reading the code might not either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

rfm added 2 commits December 20, 2024 18:10
Clarify standard operator precedence
@davidchisnall davidchisnall merged commit 0bef56a into master Dec 21, 2024
88 of 89 checks passed
@davidchisnall davidchisnall deleted the rfm-patch-2 branch December 21, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants