ObjectMapper { public void cleanup() { Reference<? extends Object> removableReference = null; while ((removableReference = referenceQueue.poll()) != null) { EntryMap removableEntry = referenceMap.get(removableReference); map.get(removableEntry.hashCode).remove(removableEntry); if (map.get(removableEntry.hashCode).isEmpty()) { map.remove(removableEntry.hashCode); } } } ObjectMapper();   ObjectMapper(boolean useNativeHashcode); T get(Object obj, S key); void put(Object obj, S key, T val); boolean contains(Object obj, S key); void cleanup(); long size();  }
@Test public void testCleanup() throws Exception { DummyObject dummy = new DummyObject(3, "abc"); ReferenceQueue<DummyObject> referenceQueue = new ReferenceQueue<DummyObject>(); WeakReference<DummyObject> dummyReference = new WeakReference<DummyObject>(dummy, referenceQueue); DummyObject otherDummy = new DummyObject(4, "def"); mapper.put(dummy, "test", otherDummy); dummy = null; TestUtil.waitForGarbageCollection(dummyReference); referenceQueue.remove(); mapper.cleanup(); assertEquals(0, mapper.size()); }