I was going through the concepts of Garbage collection in Java. From what I learnt, it says that the GC runs periodically in the background and checks for any un-referenced or unreachable objects. But when there is some sort of pressure on the memory, then only the GC is done. Also GC has phases like Marking phase, Relocating phase etc..In the following program, at the end of line 1, are the objects eligible for garbage collection as there is no guarantee that GC will always run or they are marked for GC immediately after Line 1?
Correct me if i'm wrong at any of my statements.
public class ImmutableStrings
{
public static void main(String[] args)
{
String one = "someString";
String two = new String("someString");
String three = "someString";
one = two = three=null;
System.out.println("testing "); // 1
System.out.println("testing again");// 2
}
}
At line no 1 , how many objects are marked for garbage collection? According to me, 2 objects will be eligible for GC and none marked. Answers may vary