From my understanding, garbage collection in Java cleans up some objects if nothing else is 'pointing' to that object.
My question is, what happens if we have something like this:
class Node {
public object value;
public Node next;
public Node(object o, Node n) { value = 0; next = n;}
}
//...some code
{
Node a = new Node("a", null),
b = new Node("b", a),
c = new Node("c", b);
a.next = c;
} //end of scope
//...other code
a
, b
, and c
should be garbage collected, but they are all being referenced by other objects.
How does the Java garbage collection deal with this? (or is it simply a memory drain?)
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…