Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

count of objects eligible for garbage collection?  RSS feed

 
Ranch Hand
Posts: 451
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to do some questions from interviewmocha.com and at this question I responses:  2  but my answer is wrong.




Can someone say that is the correct answer?

Thanks
 
Sheriff
Posts: 4572
286
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I say there's 1 object eligible for GC.

For these types of questions it's worth reasoning it out in your head, or out loud, or written as a reply to this topic. Can you explain your reasoning to us as to why you think it's 2?
 
Marshal
Posts: 61756
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what does the doComplexStuff method do? Does it create or assign any X instances? Or is it (as I think) a red herring having no effect on the number of instances?

I suggest you write out the code, and also write out the names of all the references, x, x2 etc. Then draw little squares each representing an instance; at the end of line 8, how many little squares have you got? How many objects have you got at the end of line 6, and how many are then eligible for GC?
 
Marshal
Posts: 6263
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think for OP is important to understand what happens in lines 11-13.

Dana, could you explain?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!