Suppose I have a Map<String,List<SomeObject>> someMap;
whose size()
ranges from 1 to 100 (this size()
stays the same for the duration of the program, the keys also stay the same!). However, in my program, the values associated with the keys are constantly changing.
The way it's currently set up is that each time I need to change someMap
's values (note that whenever I need to change the value corresponding to one key, it happens that I also need to change the values corresponding to every key), I'll overwrite the old map with a new HashMap<String,List<SomeObject>>()
, then someMap.put(someString,listOfSomeObjects)
1
to 100
times.
I am wondering how to minimise the amount of garbage generated by this program? I understand that I have a few options here; I could do what I'm currently doing, or I could rely on the clear functionality (either applied at the HashMap
level and re-put
ting the List<SomeObject>
instances into it, or applied at the valueSet()
level.
The context is a real time system where stop the world pauses are undesirable (but also I don't want to purchase a special JVM for this).