Debian Codegraph @

subprojects/inline/src/test/java/org/mockitoinline/bugs/SelfSpyReferenceMemoryLeakTest.java

raw
1 /*
2 * Copyright (c) 2019 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5 package org.mockitoinline.bugs;
6
7 import org.junit.Test;
8
9 import static org.mockito.Mockito.framework;
10 import static org.mockito.Mockito.spy;
11
12 public class SelfSpyReferenceMemoryLeakTest {
13 private static final int ARRAY_LENGTH = 1 << 20; // 4 MB
14
15 @Test
16 public void no_memory_leak_when_spy_holds_reference_to_self() {
17 for (int i = 0; i < 100; ++i) {
18 final DeepRefSelfClass instance = spy(new DeepRefSelfClass());
19 instance.refInstance(instance);
20
21 framework().clearInlineMocks();
22 }
23 }
24
25 private static class DeepRefSelfClass {
26 private final DeepRefSelfClass[] array = new DeepRefSelfClass[1];
27
28 private final int[] largeArray = new int[ARRAY_LENGTH];
29
30 private void refInstance(DeepRefSelfClass instance) {
31 array[0] = instance;
32 }
33 }
34 }