Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Garbage Collection query.

 
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" !!
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • 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


 
I'm full of tinier men! And a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic