aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ask help about gc!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "ask help about gc!!!" Watch "ask help about gc!!!" New topic
Author

ask help about gc!!!

AnthonyHan
Greenhorn

Joined: Apr 06, 2001
Posts: 4
1public class Q2 {
2 public static void main (String[] args) {
3 String s = "Hello World ";
4 String s1 = "Hello";
5 s = s1;
6 s = null;
7 s1 = null;
8 System.out.println(s);
9 }
10}
How many objects will be Garbage collected by the time execution completes Line 8?
1One
2Two
3Three
4Cannot determine
the answer is 4,I don't know why??? who can tell me?
AnthonyHan
Greenhorn

Joined: Apr 06, 2001
Posts: 4
I will attend the exam tomorrow,who can explain it for me?Thanks a lot!!!
Siobhan Murphy
Ranch Hand

Joined: Oct 19, 2000
Posts: 72
It is not possible to determine when garbage collection will take place, only to say that a piece of unused memory has become eligible for collection.
Good Luck in the exam.
Nandini Gangopadhyay
Ranch Hand

Joined: Apr 02, 2001
Posts: 79
Anthony,
Read the question, it says "will be garbage collected" and not "how many are eligible for garbage collection".
Good luck for ur exam, tell us how u did
Nandini
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Anthony,
Just to add to Nandini's answer; there are no guarantees about when the garbage collector will run or the order in which objects eligible for collection will be collected.
If the program is very small it may exit before the gc runs at all.

Hope that helps.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Amitabh Yadav
Greenhorn

Joined: Apr 07, 2001
Posts: 13
Yeah read the question carefull before answering it.Of course u cannot determine when will be the object will be collected by Garbage Collection but u can determine when the object is eligible for garbage collection.Yes sometimes ur program will end before any garbage collection takes place hence giving no chance to run the thread garbage collector.
For exam i will say read teh question carefully before naswering.
Good Luck
------------------
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: ask help about gc!!!
 
Similar Threads
Access modifier
be Garbage collected
Garbage collector
Null pointer not found
Garbage collector