Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
Aleix Vellozo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am a bit confused with the answer for Question 3 on Dan Chilsholm website:
http://danchisholm.net/july21/topic/section3/gc1.html

Which old object is he referring to here, q1 was initially set to null before the loop, so at this point no objects are eligible for gc right?

Any comments on why the answer is 9, I would appreciate. Is it because all the 9 objects created will be eligible for gc when main() exit?

Cheers.....
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 10 Q objects created by for loop.
"When the processing of line 2 begins", there are 9 objects eligible for GC and one is still hold by q1.
 
Aleix Vellozo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Wise,

I thought I had gc worked out but it seems not.

Why is the last object refereced by q1 not eligible for gc?

Cheers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic