Java - Memory Management Basics
Consider this Java code snippet:
What happens to the two
class Node {
int value;
Node next;
Node(int val) { value = val; }
}
public class Test {
public static void main(String[] args) {
Node n1 = new Node(1);
Node n2 = new Node(2);
n1.next = n2;
n2.next = n1;
n1 = null;
n2 = null;
// What happens to the Node objects in heap?
}
}What happens to the two
Node objects in heap after n1 and n2 are set to null?