My approach was to create hundred thousand local collections and populate them with random strings, something like this:
SecureRandom random = new Secure
This:
HashMap map = new HashMap();
is scoped within the loop and there are no external (long-term) references to the map created as the loop iterates. Hence each map will be eligible for garbage collection at the end of each loop iteration.
You need to create a collection of objects outside the loop, and use the loop to populate that collection.