Originally posted by Hima Nadi:
class sreejith //..1
{ //2
public static void main(String args[]) //3
{ //4
String s="hello"; //5
String s1="hello"; //6
System.out.println(s1); //7
String s3=s1; //8
s1=null; //9
s=null; //10
} //11
I always go wrong on these type of quations.
can someone explain me when objects will be garbge collected.
I know when object is no more in use.
here i presume "hello" in s will be garbage collected in line 10. why i am wrong?
Thanks Hima
I�m a beginner in
Java. I will try to help you anyway.
The s object (the s instance of the String class) will be eligible for garbage collection when it�s no more referenced, as you coded in line 10 for the s instance. This means that the Java Virtual Machine will drop this object by his own criteria.
From line 10 it�s possible s instance to be garbage collected, not before.
Hope that helps.
[ April 17, 2002: Message edited by: Sigfred Zamo ]