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

The truth in garbage collecting???????

Victor Eduardo
Greenhorn

Joined: Jul 18, 2001
Posts: 5
The question is ... when the variable sHello is elegible for collection?
public class Garbage
{
public static void main(String args[])
{
Garbage gar = new Garbage
System.out.println(gar.sayHello());
}
public String sayHello
{

String sHello = "hellllloo";
sHello = null;
return sHello;
}
}

------------------
Not certified but sooner.


Sun Certifed Programmer for Java 2 Plataform
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Victor,
First lets start with the basics:
Variables are never eligible for garbage collection!
In java, only objects can be eligible for garbage collection.
This is an important distinction because your question is worded incorrectly. It should read:
When is the object, originally referenced by sHello, eligible for garbage collection?
The answer to that is: immediately after setting the sHello variable to null. Why? Because the original object (string "hellllloo") has no references to it so the JVM makes the string eligible for garbage collection.
Regards,
Manfred.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Victor,
Would you please post the name of the mock exam that included the question.
Thanks.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited July 19, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Victor Eduardo
Greenhorn

Joined: Jul 18, 2001
Posts: 5
I made this, but i remember a very similar in this mock exam http://joppa.appliedreasoning.com/javaCert/html/JavaCertification.html
this exam consider, that the object is elegible for collection when the JVM cross the last bracket ( "}" ) in the method.
thats my problem!!
Another guy told me that the object is elegible for collection when the method sends his return...
thanks all.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The truth in garbage collecting???????