Hi,
If you analyze reference of each object -
gc1 --> null
gc2 --> some object on heap
gc3 --> some object on heap
gc4 --> gc3
gc1 --> reference to object returned by doStuff --> create localGC (--> refer some object on heap) ---> passing same reference to doStuff2 (it does nothing with it) --> return the reference of localGC.
so overall -
gc1 --> refere to same object which localGC was assigned in dostuff method.
Garbage Collector and finalize