Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Memory 清除集合对象中的引用_Memory_Collections_Hashmap - Fatal编程技术网

Memory 清除集合对象中的引用

Memory 清除集合对象中的引用,memory,collections,hashmap,Memory,Collections,Hashmap,我有一个学生类型的HashMap。Student是一个用户定义的对象,它由几个属性和另一个称为College的用户定义对象组成。现在,在使用之后,我想清除HashMap使用的所有内存,以及Student和College对象使用的所有内存。所以,在取消设置时,我是否需要显式取消Student和College对象,然后为HashMap对象分配空引用?或者只将NULL赋值给HashMap对象将释放学生和大学对象使用的内存 Map<String, Student> myMap = new H

我有一个学生类型的HashMap。Student是一个用户定义的对象,它由几个属性和另一个称为College的用户定义对象组成。现在,在使用之后,我想清除HashMap使用的所有内存,以及Student和College对象使用的所有内存。所以,在取消设置时,我是否需要显式取消Student和College对象,然后为HashMap对象分配空引用?或者只将NULL赋值给HashMap对象将释放学生和大学对象使用的内存

Map<String, Student> myMap = new HashMap<String, Student>
Student std = myMap.get("");
College col = std.getCollege();
col = null; std = null;
myMap = null;
Map myMap=newhashmap
学生std=myMap.get(“”);
学院学院=标准getCollege();
col=null;std=null;
myMap=null;

为了释放HashMap正在使用的内存,是否需要执行上述所有操作?或者取消HashMap将释放所有内存?

我刚刚找到了这个问题的答案,并了解到,当我们对任何HashMap对象调用clear方法时,它会在HashMap中的所有对象/内容上进行内部迭代,并显式地将其指定为NULL。然后将哈希映射的大小设置为0以清除哈希映射。下面是HashMap类的clear()方法的实现

public void clear() {
    this.modCount += 1;
    Entry[] arrayOfEntry = this.table;
    for (int i = 0; i < arrayOfEntry.length; ++i)
        arrayOfEntry[i] = null;
    this.size = 0;
}
public void clear(){
这是modCount+=1;
条目[]arrayOfEntry=this.table;
对于(int i=0;i

您可以在eclipse中使用jadclipse插件查看HashMap类的这些内容。

有什么帮助吗??