明确()IMPL我担心这是一个非常愚蠢的问题,但在这里有云:在Java中的LinkedList的
为什么在Java中的默认的LinkedList实现clear方法懒得走路的列表,并解开所有的节点?为什么不解开标题并将列表的其余部分连接在一起 - GC将会得到它,不是吗?
这里的方法:
/**
* Removes all of the elements from this list.
*/
public void clear() {
Entry<E> e = header.next;
while (e != header) {
Entry<E> next = e.next;
e.next = e.previous = null;
e.element = null;
e = next;
}
header.next = header.previous = header;
size = 0;
modCount++;
}
为什么走了?为什么不直接跳到header.next = header.previous = header;
?
我能想到的最好方法是帮助GC ...?这个链接http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997442表明这一点。
TIA ...
我都不同意,说外部代码无法获得对LinkedList $ Entry的引用......但是通过LinkedList $ ListItr间接你肯定可以......非常感谢! – overthink 2009-02-22 23:14:33