• Post Reply Bookmark Topic Watch Topic
  • New Topic

count of objects eligible for garbage collection?  RSS feed

 
Dana Ucaed
Ranch Hand
Posts: 406
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
 
Tim Cooke
Marshal
Posts: 4051
239
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?
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • 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?
 
Liutauras Vilda
Sheriff
Posts: 4927
334
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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!