0

Below is the reference code

public static Map<String, Long > map1 = new HashMap<String, Long >();

if i call map1.clear() , will all elements of hashmap become eligible for GC or do i need to set every element of the map explicitly to null ?

user1764879
  • 112
  • 1
  • 9
  • yes .. thank you .. i have thought that clear function given in the question is written by the user ..now understood it is the code of default clear. – user1764879 Aug 30 '13 at 09:07

1 Answers1

0

hashmap.clear() just clears all the data of the HashMap to make it reusable again.Here reusable means the same object can be reused again.So I dont think there is any role of GC here.

Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
  • my intention of mentioning GC is ..in java if objects are still referred ..they will not be eligible for Garbage collection ..when we dont make the array object to null , then the refrence is not released and hence memory leak .. some one please correct me if i am wrong .. – user1764879 Aug 30 '13 at 10:03