You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Storing a nil value to a weak reference is, by my reading of the documentation, supposed to remove the weak reference.
Mostly that's what objc_storeWeak() does, but there is a situation where it doesn't do that:
Consider this sequence of events:
an object is stored to an address using objc_storeWeak(), creating a weak reference
the object is then deallocated, leading to the pointer being zeroed, but the runtime still keeping track of the address
then we want to stop using that address as a weak reference, so we use objc_storeWeak() to store null to it
however, because the old value and the new value are both zero, the existing implementation doesn't remove the weak reference.
The code looks like this:
// If the old and new values are the same, then we don't need to do anything.
if (old == obj)
{
return obj;
}
perhaps it should be
// If the old and new values are the same, then we don't need to do anything.
if (obj != NULL && old == obj)
{
return obj;
}
The text was updated successfully, but these errors were encountered:
I'm fairly confident my reading of what this function should do is correct, and the code change obviously fixes it to avoid leaking reference information (for code in the base library which assumes that we can call it to delete a weak reference).
If so, I guess the associated comment would need to be improved too.
Storing a nil value to a weak reference is, by my reading of the documentation, supposed to remove the weak reference.
Mostly that's what objc_storeWeak() does, but there is a situation where it doesn't do that:
Consider this sequence of events:
an object is stored to an address using objc_storeWeak(), creating a weak reference
the object is then deallocated, leading to the pointer being zeroed, but the runtime still keeping track of the address
then we want to stop using that address as a weak reference, so we use objc_storeWeak() to store null to it
however, because the old value and the new value are both zero, the existing implementation doesn't remove the weak reference.
The code looks like this:
// If the old and new values are the same, then we don't need to do anything.
if (old == obj)
{
return obj;
}
perhaps it should be
// If the old and new values are the same, then we don't need to do anything.
if (obj != NULL && old == obj)
{
return obj;
}
The text was updated successfully, but these errors were encountered: