DZone Java Zone
Follow
Memory Leak Due To Mutable Keys in Java Collections
Java Collections components (such as Map, List, Set) are widely used in our applications. When their keys are not properly handled, it will result in a memory leak. In this post, let’s discuss how incorrectly handled HashMap key results in OutOfMemoryError. We will also discuss how to diagnose such problems effectively and fix them.
HashMap Memory LeakBelow is a sample program that simulates a memory leak in a HashMap due to a mutated key: