aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
Author

Garbage Collection

mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
public class BettyAck {
public static void main(String argv[]){
BettyAck b =new BettyAck();
}
public BettyAck() {
Integer x = new Integer(10);
findOut(x);
Integer y = new Integer(99);
Integer z = y;
z = null;
findOut(y);
//here
}
public void findOut(Integer y){
y = null;

}
}


Given the following code, how many objects will be eligible for garbage collection on the line with the comment //here
Lakshman Arun
Greenhorn

Joined: Sep 24, 2008
Posts: 19
No object is eligible for GC at line //here
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

mukki please tell from where you copied this question!!!


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
sweety sinha
Ranch Hand

Joined: Jul 07, 2008
Posts: 76
i think Lakshman Arun is wright
mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
i got from esnips pdf

but isn't b available for GC...because it is not set to null
vipin jain
Ranch Hand

Joined: Aug 24, 2008
Posts: 122
No object is eligible for GC at line //here


Best Regards,<br />Vipin<br />MCA, SCJP5, SCWCD in progress
mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
how about this

BettyAck b =new BettyAck();

isn't b available for GC
ramesh maredu
Ranch Hand

Joined: Mar 15, 2008
Posts: 210



b is a reference variable, reference variables are never eligible for GC.The object created(new BettyAck()) is also not eligible for GC,as it has reference from b.


SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
Arabinda Das
Greenhorn

Joined: Oct 03, 2008
Posts: 3
we have not lost the reference of 'b' object till now. so its not available for GC
mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection