• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection query.

 
Kirtipriya Jammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , i have a question on garbage collection...

When line 16 is reached, how many objects will be eligible for garbage collection?


My understanding is attached in the file.
So is the answer 2 ?

pic1.png
[Thumbnail for pic1.png]
 
Kirtipriya Jammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh that should be "When line 15 is reached" !!
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say 1.

When we reach line 12 we have an object map as in the gc1-line12.png.

When we then de-ref a1, b1 and b2 refs, we only free the a1:Alpha instance, since the b1:Beta and b2:Beta still will have references from the static :Alpha via a2:Alpha.b1 and from a2:Alpha.b2.

Right??

The confusing bit of this question is that they use the variable names b1 and b2 in two different scopes. If you rename them as I did on the images, then it is quite clear.
gc1-line12.png
[Thumbnail for gc1-line12.png]
Objects and refs after line 12
gc1-line13.png
[Thumbnail for gc1-line13.png]
Objects and refs after line 13
 
Kirtipriya Jammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ove . !!

the foremost mistake i did was .. i put the static variable Beta b1 inside the Object Alpha.. i realized this after seeing your diagram.

Static variable cannot be an instance variable .. its a class variable .

Now i get the answer 1


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic