jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes gabage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "gabage collection" Watch "gabage collection" New topic
Author

gabage collection

aruna ver
Greenhorn

Joined: Jun 24, 2002
Posts: 8
hi
in the following code

1. class myclass
2.{
3. public static void main(String [] args){
4. string s1 = "gabage"
5. string s2 = "collect"
6. string s3=s1+s2;
7. s1=null;
8. s1=s3
9. s2=s1;
}}
What is the ealiest point when the memory allocated to s1 can be realsed is it line 7 or after line 9
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Welcome to the Ranch.
Please notice that your displayed name doesn't comply with the naming policy. Please adjust to it.
Let's suppose the two variables were created with new. In that case the answer is 7, because so far the only refererence to the object was s1; and this reference is lost via the assignation of null.
In the exam you will not see a question about eligibility of string literals for g.c. You will only see "normal" objects. In fact the correct answer is that the objects computed from string literals are not normally g.ced


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gabage collection
 
Similar Threads
problem in generics(sun accesibility test)
Garbage Collection and the String Pool
String problem
GabageCollection
Garbage Collection and the String Pool