• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC Question

 
Lalit mishra
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for(int i =0;i<5;i++)
{
Demo d = new demo();
}
//line 1




How many object can be garbage collected at line 1
5 or 4
since even if d is out of scope at line 1
but it is still having reference to object demo??
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5 objects will be garbage collected.

Reference is out of scope,meaning at line 1 no reference is for demo object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic