Hi,
I’ve got a garbage collection problem relating to java.util.HashMap. After profiling, I’ve found that the garbage collector (GC) is using around 5% of the processor time. The problem is that I create lots of HashMap.Entry’s since I’m always adding to HashMaps then calling clear() to empty the HashMap again, and repeating.
I’m using the HashMaps in the A* path finding code I’ve been working on. I use HashMaps instead of ArrayLists to achieve constant-time get() and add()/put() operations which has sped up the algorithms, but contributed to GC time. That’s because with every put(), a new HashMap.Entry is created.
What should I do to avoid the huge amount of HashMap.Entry object creation? I’m 99% certain that the HashMap.Entry creation is the problem since NetBeans profiler says that I have 248 ‘live’ instances of HashMap.Entry lying around, but I’ve allocated 58,000 instances over the program’s life. Those 248 live instances comprise 6,000 bytes which is 6% of the ‘live’ bytes.
Any thoughts appreciated
Thanks,
Keith