I came acroos the following qn in a mock exam.
At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
1.Before statement labeled 1
2.Before statement labeled 2
3.Before statement labeled 3
4.Before statement labeled 4
5.Never.
the ans they have given is 4. But I think garbage collection can not be forced or determined. Can anyone please clarify me.
Thanks
Charu