Java HashMap.clear() 和 remove() 内存是否有效?
考虑一下 follwing 代码:HashMap.clear()
/**
* Removes all of the mappings from this map.
* The map will be empty after this call returns.
*/
public void clear() {
modCount++;
Entry[] tab = table;
for (int i = 0; i < tab.length; i++)
tab[i] = null;
size = 0;
}
看起来,对象的内部数组()永远不会缩小。因此,当我向映射添加 10000 个元素时,在该调用之后,它将在其内部数组中保留 10000 个 null。所以,我的问题是,JVM如何处理这个无的数组,因此,内存是有效的吗?table
Entry
map.clear()
HashMap