Java - Circular Garbage Collection
        Posted  
        
            by aloh
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by aloh
        
        
        
        Published on 2010-05-10T03:39:37Z
        Indexed on 
            2010/05/10
            3:48 UTC
        
        
        Read the original article
        Hit count: 331
        
java
A <-> B <-> C <-> D <-> A...
// A is firstNode, D is lastNode
        if ( length == 1 )
        {
            firstNode = null;
            lastNode = null;
            firstNode.next = null;
            firstNode.prev = null;
        }
        else
        {
            Node secondNode = firstNode.next;
            Node secondToLast = lastNode.prev;
            firstNode.next = null;
            firstNode.prev = null;
            lastNode.next = null;
            lastNode.prev = null;
            secondNode.prev = null;
            secondToLast.next = null;
            firstNode = null;
            lastNode = null;
        }
That should send everything in between as candidates for garbage collection, I hope?
© Stack Overflow or respective owner