R
Razvan
Hi !
Take a look at the following code:
public class CDummy
{
public static void main(String args[])
{
System.out.println("CDummy.");
for(int ii=10; ii>=0; ii--)
{
String tmp = Integer.toString(ii);
System.out.println(tmp);
}
System.out.println("END");
}
}
When the program reached the line that prints "END", how many 'tmp'
string objects are elligible for
garbage collection ?
Valid answers:
1
10
11
20
none
I choosed 10, the right answer is 11. The reason for this is the fact
that even if the variable tmp is out of scope it is STILL holding a
reference to the last 'tmp' string. Is that true ?!! At the above
mentionated line there is no way in the whole program to access any
temporary string. Normally they should ALL be garbage collected. Can
the out of scope variable tmp prevent the garbage collector from
collecting the last string ?
Regards,
Razvan
Take a look at the following code:
public class CDummy
{
public static void main(String args[])
{
System.out.println("CDummy.");
for(int ii=10; ii>=0; ii--)
{
String tmp = Integer.toString(ii);
System.out.println(tmp);
}
System.out.println("END");
}
}
When the program reached the line that prints "END", how many 'tmp'
string objects are elligible for
garbage collection ?
Valid answers:
1
10
11
20
none
I choosed 10, the right answer is 11. The reason for this is the fact
that even if the variable tmp is out of scope it is STILL holding a
reference to the last 'tmp' string. Is that true ?!! At the above
mentionated line there is no way in the whole program to access any
temporary string. Normally they should ALL be garbage collected. Can
the out of scope variable tmp prevent the garbage collector from
collecting the last string ?
Regards,
Razvan