Search code examples
javamemory-managementconcurrenthashmap

Does removing item from Hashmap open it to GC?


Does calling .remove() on a ConcurrentHashMap object open that object to be garbage collected? The Javadocs say a lot about removing the mapping but never mentions what happens to the object.

I'm having a bit of a memory leak somewhere and I'm wondering if this might be it. Should I nullify objects in my hashmap before removing?


Solution

  • Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the collection contains one or more such elements.

    so as e==null it becomes eligible for GC, We do not achieve anything by Nullifying it ever in java.