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 ?
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 ?
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.