-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Why does a stubOnly mock keeps reference of the last invocation? #348
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
Comments
This seems reasonable. I don't think we do this for Mockito 2.0, but 2.1 instead. It does require an investigation if this is backwards incompatible though. |
This is not a bug, otherwise mockito can't record the stub itself. |
@bric3 If you don't mind, could you elaborate on this (5 years later)? I'm also facing a memory leak like this and found this ticket. |
I wonder why I did say that back then, this incorrect. 🧐 |
Yeah, that looks like what I'd expect too. Considering there are test cases that fail, I guess there's a risk that some projects accidentally use the incorrect behaviour when pure stubs are used. In that case, I suppose the migration is easy: Don't use |
I was looking at a memory leak caused by a mock in our tests and I noticed that creating a mock this way
will still keep the last invocation in memory:
mockito/src/main/java/org/mockito/internal/stubbing/InvocationContainerImpl.java
Line 141 in c303e49
mockito/src/main/java/org/mockito/internal/verification/SingleRegisteredInvocation.java
Line 16 in c303e49
I was wondering if that was on purpose? I thought the whole point of
stubOnly()
was to prevent allocating too much memory for nothing by preventingverify()
on a mock. I think something like that would make more sense:The text was updated successfully, but these errors were encountered: