pkdevboxy / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

java.lang.OutOfMemoryError #400

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Write simple JUnit test with this test:

    @Test
    public void testOutOfMemory() {
        Object obj = mock(Object.class);
        when(obj.toString()).thenReturn("asdf");
        for (int i = 0; i < 1000000; i++) {
            obj.toString();
        }
    }

What is the expected output? What do you see instead?
memor is not consumed and java.lang.OutOfMemoryError is not thrown

What version of the product are you using? On what operating system?
Mockito 1.8.5, 1.9.5
OSX 
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)

Original issue reported on code.google.com by xxb...@gmail.com on 21 Nov 2012 at 11:10

GoogleCodeExporter commented 8 years ago
Hi,

Actually, that behavior is expected, as Mockito will remember each invocations 
the code is doing. So there will objects created for each interactions in the 
1000000 loop. This is needed as interactions might be verified later.

That being said Hynek Mlnarik did a great job to allow Mockito to not register 
invocations, the work is still in master though. Keep in mind this is not yet 
released, but you can enable this feature by declaring the mock like that :

mock(Object.class, withSettings().stubOnly());

Does that work for you ?

Original comment by brice.du...@gmail.com on 22 Nov 2012 at 11:55

GoogleCodeExporter commented 8 years ago
I'm tempted to invalidate this issue, feel free to raise your hand if you feel 
otherwise.

Original comment by brice.du...@gmail.com on 4 Dec 2012 at 3:17