File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gabage collection

 
aruna ver
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic