void (@NotNull IntObjectMap<Object> map) { map.put(1, this); map.put(2, this); map.put(3, strong = new Object()); map.put(4, this); Iterator<IntObjectMap.Entry<Object>> iterator = map.entrySet().iterator(); assertTrue(iterator.hasNext()); strong = null; for (int i=0; i<10; i++) { if (map.get(3)==null) break; GCUtil.tryGcSoftlyReachableObjects(() -> map.get(3)==null); } if (map.get(3) == null) { List<Integer> keys = ContainerUtil.map(ContainerUtil.collect(iterator), e -> e.getKey()); assertFalse(keys.contains(3)); } else { // bad luck - iterator has started with 3 assertEquals(3, iterator.next().getKey()); } }