File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes need help with garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help with garbage collector" Watch "need help with garbage collector" New topic
Author

need help with garbage collector

gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
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

Joined: Aug 31, 2004
Posts: 11343

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.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
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

Joined: Apr 13, 2007
Posts: 29
I also see only one eligible for GC.
 
 
subject: need help with garbage collector
 
Similar Threads
Garbage Collection
garbage collection question
GC Question.
Doubt - Reg: GC
help in garbage collection question