Tomasz Rycerz wrote:This is my first post here.
Tomasz Rycerz wrote:The correct answers are d) and e). My problem is with the explanation to option e):
"Option (e) is correct. If you marked this option incorrect, think again. The question wants you to select the correct statements, and this is a correct statement. You may argue that at least two objects were already made eligible for garbage collection at line 1, and you are correct. But because nothing changes on line 2, at least two objects are still eligible for garbage collection"
You may argue that at least two objects were already made eligible for garbage collection at line 1, and you are correct.
Paul Clapham wrote:
You may argue that at least two objects were already made eligible for garbage collection at line 1, and you are correct.
I'm with Tomasz in saying this statement is wrong. Only one object was made eligible for GC there, no?
Roel De Nijs wrote:At line 1 there is 1 object eligible for GC (namely the object created on the 2nd statement of the main-method)
Guillermo Ishi wrote:This is an example of a question you can answer by eliminating the wrong answers. A-c all imply you know when gc will run, but in fact you only know when it may run.
Jo Gupta wrote:The correct answer apparently is "2". My question is which are these two? Is it correct that these 2 are 1) the original object that c was referencing to before statement c=b and 2) the object that b was referencing (a.aob referencing b in the statement c.aob=a.aob given a.aob=b) ?
Roel De Nijs wrote:Output:
a -> A@68dd6317 (aob -> null)
b -> A@1e94b0ca (aob -> null)
c -> A@33e2ad75 (aob -> null)
d -> A@66e9f6ef (aob -> null)
d.aob -> A@a52f9b2 (aob -> null)
--- start ---
a -> A@68dd6317 (aob -> A@1e94b0ca)
b -> A@1e94b0ca (aob -> A@68dd6317)
c -> A@33e2ad75 (aob -> A@1e94b0ca)
c -> A@1e94b0ca (aob -> A@68dd6317)
--- end ---
a -> A@68dd6317 (aob -> A@1e94b0ca)
b -> A@1e94b0ca (aob -> null)
c -> A@1e94b0ca (aob -> null)
d -> A@a52f9b2 (aob -> null)
In section 1 (before --- start ---) you'll find all created objects, in section 3 (after --- end ---) you'll find the final state of all reference variables. So any object wihich is mentioned in section 1 but not in section 3 is eligible for GC
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|