| Author |
object elligible for garbage collection
|
Isabel Wanderley
Ranch Hand
Joined: Aug 24, 2002
Posts: 42
|
|
The question is : What is the earliest line after which the object created on //A is eligible for garbage collection? (Select one correct answer) I thought was after line 3 but the answer is after line 2 anyone can explain me that ? Thanks! <code> public class Test059 { public static void main(String args[]) { Byte b1 = new Byte("127"); //A Byte b[] = new Byte[2]; b[1] = b1; b1 = null; //1 b[1] = null; //2 System.out.println(b1); //3 System.out.println(b[1]); //4 } } </code>
|
 |
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
|
|
|
Can't be after line 3, since line 3 doesn't do anything that would cause an object to become unreachable.
|
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
|
 |
Isabel Wanderley
Ranch Hand
Joined: Aug 24, 2002
Posts: 42
|
|
hahahahahahaha Sorry I just read the line worng.... Sorry!!!
|
 |
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
|
|
Hi, can you use the square brackets instead of the pointy ones for your code tags?
|
 |
Matt Kidd
Ranch Hand
Joined: Jul 17, 2002
Posts: 256
|
|
|
For my own clarification, wouldn't the object declared in the //A line be ready for garbage collection after line //1 beginning with //2?
|
 |
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
|
|
Originally posted by Matt Kidd: For my own clarification, wouldn't the object declared in the //A line be ready for garbage collection after line //1 beginning with //2?
b[1] is still referring to the object ("127") so at that point in time, that object is still not eligible for garbage collection...
|
 |
Matt Kidd
Ranch Hand
Joined: Jul 17, 2002
Posts: 256
|
|
|
How? Doesn't [CODE]b1 = null;[/CODE} take the reference away from the Byte object?
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
|
Yes but b[1] is still referencing the Byte object even though b1 has no reference to it anymore.
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Matt Kidd
Ranch Hand
Joined: Jul 17, 2002
Posts: 256
|
|
*grumble, grumble, grumble* ebil twick question...juuuust ebil. (After I posted I looked at the code again and I got that feeling in my gut that was the case)
|
 |
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
|
|
Search your feelings Matt... you know them to be true
|
 |
 |
|
|
subject: object elligible for garbage collection
|
|
|