erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

stopMocking doesn't call because of retain cycle while stubbing #356

Closed lebad closed 4 years ago

lebad commented 6 years ago

This issue happens all the time when I stub a mock object and use andReturn with this mock object or use OCMArg with reference to this mock object.

Example with singleton stubbing:

id singletonClassMock = OCMClassMock([Singleton class]);
OCMStub(ClassMethod([singletonClassMock shared])).andReturn(singletonClassMock);

dealloc is never called as well as stopMocking

Example with OCMArg stubbing:

OCMStub([mock methodWithBlock:([OCMArg invokeBlockWithArgs:mock, nil])]);

So we have memory leaking here and should manually call stopMocking to prevent unexpected behavior.

Is there any way to fix this problem?

Thanks!

ian-twilightcoder commented 6 years ago

I'm pretty sure once you stub a class method you have to manually stop mocking.

ian-twilightcoder commented 6 years ago

Although, I don't really know why you have to manually call -stopMocking the more I look at it. Even if you do, the mock object still doesn't appear to deallocate, maybe there's a leak hiding here somewhere? The trigger appears to be stubbing a class method.

erikdoe commented 4 years ago

I think this is fixed by #363, which is released in OCMock 3.5. Can you double-check, please?

erikdoe commented 4 years ago

Closing due to inactivity. Assume fixed.