Which is the earliest line in the following code after which the object created on line // 1 can be garbage collected?
public class Main{ private Object o; void doSomething (Object s){ o = s; } public static void main (String args []){ Object obj = new Object (); // 1 Main tc = new Main (); //2 tc.doSomething (obj); //3 obj = new Object (); //4 obj = null; //5 tc.doSomething (obj); //6 } /* www . ja va 2 s. c o m*/ }
Select 1 option
Correct Option is : F
An object can be made eligible for garbage collection by making sure there are no references pointing to that object.
You cannot directly invoke the garbage collector. You can suggest the JVM to perform garbage collection by calling System.gc ();