Howdy -- OK, let me try to clear up the GC/scope issue. Because I'm pretty sure that I'm the idiot who was not clear enough in the earlier posts about this topic. The context of the below-method-scope-level was referring to loop and block variables, not to other gc triggers somewhere within the method (I'll explain more below)
I must have led people to interpret that phrase in a way other than I intended. Yikes! And if Alfred interpreted it that way, then I bet tons of other people did too, because he's one of the brightest crayons in the box around here
SO here it is again, hopefully this time with more detailed explanations:
We have two ways to know an object is no longer referenced:
1) The reference is deliberately nulled or reassigned, and it is the only live reference (i.e. reachable from a live thread)
2) The reference goes out of scope.
So, it is point #2 where the scope-below-method-level comes into play. You will not be asked about GC with respect to references that go out of scope BEFORE a method completes. But that's only when the issue is about SCOPE.
If the issue is from point #1, then you will definitely need to know exactly at which point an object becomes eligible for GC.
Again, you ARE expected to know when, in a method, objects become eligible, but NOT because the reference went out of scope "early", in other words, you don't have to know that an object became eligible because its reference went out of scope somewhere BEFORE the method ended. This really just means a loop or other local block variable that is "less than method scope".
Please please please write again if I just made it even more confusing, and my apologies. But I think my "less than method scope" comment needs to be viewed in the thread where we discussed it, because we were discussing the scope of LOOP variables. : )
Of course, Alfred is one of the few people on the planet to get even CLOSE to a 90% (and all the others are also here on javaranch, BELIEVE me, people do NOT get these kind of scores on this exam), but what's frustrating for him is that he knows he could have done even better if the wording of the questions had been better!! (And frustrating for me because, after all the analysis Alfred has done for me, I am certain that he would have as well).
So yes, I have to say that the GC questions are tricky, but they do follow the rules very explicitly. A reference is either:
1) Nulled
2) Reassigned
3) Goes out of scope (at the method level!!)
Any of those three are what you must be able to recognize, with reasons 1 and 2 potentially happening ANYWHERE in a method. The difficulty is that you won't see many questions that say:
1. Object o = new Object();
2. o = null;
3. // more code
How many objects are eligible for GC at line 3?
But the exam would put that question in a much more complex example, with the o referenced passed into some other constructor and then some method, that then reassigns the copy of o, etc., etc., etc.
I'm still going to congratulate Alfred for being one of the top scorers in the world! But I also believe that phrasing on the questions may have prevented him from going further.
Alfred, for gosh sakes get out there and celebrate. I just wish you could know how amazing your score really was. As far as we're concerned, there's really no difference between 90 and 100, because you have to allow for some questions to be misinterpreted, no matter how heavily they're tested.
Cheers,
Kathy "dances with garbage" Sierra
