can we invoke gc explicitly in a mock exam question it is found that set reference to null and reassigning it to another object there is a chance of getting garbage collected codei s like this cosider this is in main method 1)Strin s1 = "aaa"; 2)Strin s2 = "bbb"; 3)Object a = s1; 4)a = null; 5)a = b; Quetion is where is object a likely to get garbage collected line numbers is given as choice Please clarify Rk Raj
1)Strin s1 = "aaa"; 2)Strin s2 = "bbb"; 3)Object a = s1; 4)a = null; 5)a = b; Here variable is available for garbage collection just before line no:5 or to put in another way, after the execution of line no:4.
Balaji: Here variable is available for garbage collection... a small correction... What you seem to say is correct, however the variable is not the one which is being GC. The object referenced by the variable is being GC, since it has no further references. Regds. - satya
Take a Minute, Donate an Hour, Change a Life
here should be small corection it should be String //Strin U dont b for which it is refering // not clear for b; String a="skldjf"; String s2 ="adfkl"; Object a=s1; a=null; //if u say a to null still s1 is referring to that string object no garbage collection. i hope it is clear. suresh
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Download Free Java APIs to Work with Office Files and PDF