java知道一个reference怎么删掉它指向的内存空间? (转载)# Java - 爪哇娇娃
s*i
1 楼
【 以下文字转载自 JobHunting 讨论区 】
发信人: sci (ence), 信区: JobHunting
标 题: java知道一个reference怎么删掉它指向的内存空间?
发信站: BBS 未名空间站 (Thu Jun 9 11:51:36 2011, 美东)
java。
维护了一个 HashMap 和 List, A是我自己定义的一个class.
每次new一个A之后,先add到 list里面,然后再 加到map里面。
A a = new A();
list.add(a);
map.put(key, a);
这个测试过没问题,a只被创建一次。
问题是我需要写一个remove ,就是拿到map里面的value,这个value其实是一个
reference(相
当于指针)。然后需要delete掉对应的list里面的内容。
如果在c/cpp,这个轻而易举,但是不知道在java怎么弄?谢谢!
发信人: sci (ence), 信区: JobHunting
标 题: java知道一个reference怎么删掉它指向的内存空间?
发信站: BBS 未名空间站 (Thu Jun 9 11:51:36 2011, 美东)
java。
维护了一个 HashMap
每次new一个A之后,先add到 list里面,然后再 加到map里面。
A a = new A();
list.add(a);
map.put(key, a);
这个测试过没问题,a只被创建一次。
问题是我需要写一个remove ,就是拿到map里面的value,这个value其实是一个
reference(相
当于指针)。然后需要delete掉对应的list里面的内容。
如果在c/cpp,这个轻而易举,但是不知道在java怎么弄?谢谢!