Hi, Damon. But once dequeued, old node is dead object. The pointer(h.next) from dead object to alive/dead object makes no difference to GC. So I thinks h.next=h is meaningless.
And, why isn't it h.next=null ? On Mon, Jun 22, 2020 at 12:18 AM Damon Hart-Davis <d...@exnet.com> wrote: > By avoiding spurious pointers to h.next keeping the ’next’ item alive > longer than necessary. > > Rgds > > Damon > > On 21 Jun 2020, at 12:59, Robert Lu <robberp...@gmail.com> wrote: > > Hi, > On java.util.concurrent.LinkedBlockingQueue#dequeue > https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java#L217 > : > > private E dequeue() { > // assert takeLock.isHeldByCurrentThread(); > // assert head.item == null; > 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; > } > > Why does h.next = h help GC? > > -- > Robert Lu <robberp...@gmail.com> > About me: https://www.robberphex.com/about-me > > _______________________________________________ > hotspot-gc-use mailing list > hotspot-gc-use@openjdk.java.net > https://mail.openjdk.java.net/mailman/listinfo/hotspot-gc-use > > > -- Robert Lu <robberp...@gmail.com> About me: https://www.robberphex.com/about-me
_______________________________________________ hotspot-gc-use mailing list hotspot-gc-use@openjdk.java.net https://mail.openjdk.java.net/mailman/listinfo/hotspot-gc-use