Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help with garbage collector

 
gylph knor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, could anybody explain which two objects would be eligible for garbage collection after line marked 6 in the following code :-


class C
{
public static void main(String a[])
{
C c1=new C();
C c2=m1(c1);
C c3=new C();
c2=c3; //6
anothermethod();
}
static C m1(C ob1){
ob1 =new C();
return ob1;
}
}

[ June 14, 2008: Message edited by: gylph knor ]
[ June 14, 2008: Message edited by: gylph knor ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only see one eligible -- the object that was created in m1 and assigned to c2. How do you see it?

(Please use Code Tags.)
 
gylph knor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually this question was asked in a test and the answer given was 2.
i also coudn't figure out the 2 objects, thats why i posted it here.
[ June 15, 2008: Message edited by: gylph knor ]
 
Ravikanth Reddy Bapathi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also see only one eligible for GC.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic