Ben Synes wrote:Im just curious as to why in and i3 are not considered as Objects being valid for garbage collection. Is it that they are reference variables pointing to Objects?
Yes. Don't confuse variables and objects; garbage collection only collects the objects, although when it does so it has to take into account whether there are variables which refer to the objects.
And if so, is it that when I take the exam, and see any similar questions, I dont consider the actually reference variable at all per se.? Any help greatly appreciated.
I don't know about the exam, but in general when you're trying to figure out what objects are available for garbage collection it can be confusing if you refer to an object by the name of a variable which refers to that object. It gets especially confusing when the variable is changed to refer to some other object. So when you see "A thing = new B()" try not to call that B object "thing".