所有!
我在LinkedBlockingQueue中发现了奇怪的代码:
private E dequeue() {
// assert takeLock.isHeldByCurrentThread();
Node<E> h = head;
Node<E> first = h.next;
h.next = h; // help GC
head = first;
E x = first.item;
first.item = null;
return x;
}
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么我们需要局部变量h?它对GC有什么帮助?