Which of the following statements are true? 1) The automatic garbage collection of the JVM prevents programs from ever running out of memory 2) A program can suggest that garbage collection be performed but not force it 3) Garbage collection is platform independent 4) An object becomes eligible for garbage collection when all references denoting it are set to null.
The correct answers, according to Marcus are: 2) and 4). Surely 4) is not a correct answer as an object is eligible for garbage collection when all references to it are set to denote another object, or to null? Siobh�n
Indu Thanks for your response. For example, say you create 2 objects a and b, where a denotes one object and b denotes another. After line 3 below, a denotes the same object as b, but there is no reference to the object denoted by a originally. Therefore the object denoted by a is now eligible for garbage collection. Isn't it? The object is no longer accessible. In this example there was no expression setting anything to null. I'd be glad if someone could clear this up for me, as I thought I understood the concept.
I think you may be answering a different question to the one I was asking. I asked if the statement was true that... An object becomes eligible for garbage collection when all references denoting it are set to null.
Whereas you appear to be answering the question is it true that "The only circumstances under which an object becomes eligible for garbage collection is when all references denoting it are set to null".. Not the addition of "The only circumstances etc etc".. Subtle but important. Marcus
------------------ http://www.jchq.net Mock Exams, FAQ, Tutorial, Links, Book reviews ================================================= Almost as good as JavaRanch =================================================
Thanks for the response Marcus. When I was doing the exam I thought the question was: "Is it true that an object becomes eligible for garbage collection when all references denoting it are set to null, and this is the only way. Setting a reference to another object just isn't enough" When answering it I thought: Not true, there are other ways of making an object eligible for gc, e.g. setting any references to it, to other objects. Incidently, thanks for your 3 sets of exams. I found them very helpful, and I learnt a lot from them.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop