Use the old association policy to determine whether to release an object
This commit has been augmented to address the comments in
@@ -166,12 +166,17 @@ static void setReference(struct reference_list *list,
lock = lock_for_pointer(r);
lock_spinlock(lock);
}
- r->policy = policy;
- id old = r->object;
- r->object = obj;
+ @try
+ {
if (OBJC_ASSOCIATION_ASSIGN != r->policy)
{
- objc_release(old);
+ objc_release(r->object);
+ }
+ }
+ @finally
+ {
+ r->policy = policy;
+ r->object = obj;
}
if (needLock)
{
