Here you are creating two references of Object A
like a1
and a2
.
First, you are assigning value of a1
to a2
.So after setting value to a2
, a1
is allowed for GC. But there will be no change in reference a2
.
You can also check this blog for Garbage Collection: