eric_the_animal
eric_the_animal

Reputation: 432

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?

Upvotes: 1

Views: 509

Answers (1)

RishiKesh Pathak
RishiKesh Pathak

Reputation: 2272

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.

Upvotes: 1

Related Questions