I use a large (millions) entries hashmap to cache values needed by an algorithm, the key is a combination of two objects as a long. Since it grows continuously (because keys in
Clear the hashmap:
hashmap.clear();
Then force a garbage collector run:
Runtime.getRuntime().gc();
This is the Javadoc page for Runtime.gc().