-
Notifications
You must be signed in to change notification settings - Fork 610
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
malloc error on recursive/chained calls to stubbed method #123
Comments
I have tried this with the same result:
|
Could you set a breakpoint on the malloc error and post the result here? In case you haven't done this before: http://stackoverflow.com/questions/14045208/how-to-set-a-breakpoint-in-malloc-error-break-to-debug |
I did it, but all I see is assembly, maybe I'm doing something wrong.
I'm starting to think that I am doing something wrong with the mock too. I am mocking a method of "MyClass" and I am testing another one of the same class, using the mock for the call, i mean:
|
NSInvocation and ARC don't play together very well. It's causing a double-release. You declared MyObjectWithAction as a local strong variable. However, the value gets assigned by NSInvocation, which takes a "void *" argument, so ARC has no way to know an object came into scope and does not add a retain. However, it will add a release when it goes out of scope. Boom, that's a crash. Declare the variable as __unsafe_unretained so ARC doesn't touch it. If you want, declare one variable as __unsafe_unretained, use getArgument:atIndex: on that, and then immediately assign to a local (normally declared) variable, which will then have a local strong reference, if you want to guard against deallocation during the block. |
I get it. So it could not be an OCMock problem. |
I'm trying to stub an async method in a partial mock:
But inside "action()", I'm calling to "myMethodWithParam:" one more time (but this time with a "MyObjectWithAction" without action).
...and I'm getting:
The text was updated successfully, but these errors were encountered: