Given the code. Which line of code marks the earliest point that an object referenced by myInt becomes a candidate for garbage collection?
1 public void doStuff() {
2 Integer arr[] = new Integer[5];
3 for (int i = 0; i < arr.length; i++) {
4 Integer myInt = new Integer(i);
5 arr[i] = myInt;
6 }
7 System.out.println("end");
8 }
A) Line 4
B) Line 5
C) Line 6
D) Line 7
what should be the answer ??more important is why??!!
Harsh when you post a question, it is mandatory to Quote Your Sources. So please tell us where you copied this question from. Also as you can see that myInt is assigned to the array arr, so the objects that myInt points to will be eligible for garbage collection when arr goes out of scope...
It is never available for GC inside the for loop (Because each time a new myInt is created it's reference is assigned to one of the array references). So I guess line 7 where the array is out of scope. Ranchers please correct me if I am wrong.
Thanks a lot Ankit...and by the way congrats for your score..!!!
More specifically the answer should be Line 8??what say??yeah it's not given in option..but still it should have been given then..