Skip to content

Commit

Permalink
Merge pull request #11 from ashdnazg/feature/check-weak
Browse files Browse the repository at this point in the history
NSInvocation+OCMAdditions: don't retain deallocating objects.
  • Loading branch information
ashdnazg authored May 22, 2022
2 parents 0f2f5a8 + 6c771c4 commit 5fe0c6b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Source/OCMock/NSInvocation+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ - (void)retainObjectArgumentsExcludingObject:(id)objectToExclude
NSMutableArray *retainedArguments = [[NSMutableArray alloc] init];

id target = [self target];
if((target != nil) && (target != objectToExclude) && !object_isClass(target))
// We don't want to retain a currently deallocating target, we check this by calling
// allowsWeakReference which returns NO in exactly this case.
if((target != nil) && (target != objectToExclude) && !object_isClass(target) &&
[target allowsWeakReference])
{
// Bad things will happen if the target is a block since it's not being
// copied. There isn't a very good way to tell if an invocation's target
Expand Down Expand Up @@ -109,7 +112,9 @@ - (void)retainObjectArgumentsExcludingObject:(id)objectToExclude
// case do not retain the argument. Note: Even though the type is class the
// argument could be a non-class, e.g. an instance of OCMArg.
}
else
// We don't want to retain a currently deallocating object, we check this by calling
// allowsWeakReference which returns NO in exactly this case.
else if([argument allowsWeakReference])
{
[retainedArguments addObject:argument];
}
Expand Down

0 comments on commit 5fe0c6b

Please sign in to comment.