Originally posted by Jon Coltman:
[B]Padmini,
The example question given by Tony is a good answer to your question:
" An object will be garbage collected if the last reference to it is removed. "
----------
Hi Tony and Jon,
Let me have an example like this:
String obj = new String( "hello" ); //Line 1
String str = obj; //Line2
String xys = str; //Line3
Now , the last reference to the string "hello" is xyz.
So I set xyz to null.
Now,
" An object will be garbage collected if the last reference to it is removed. "
As per this logic, will the object be Garbage collected???
Thanks
Padmini
.
[This message has been edited by padmini Babu (edited June 21, 2001).]
Always Belive On Logic!!
Originally posted by Hassan Naqvi:
Hi padmini,
An object will become candidate for garbage collection untill unless it's reference is lost by the programme(or you may say "solution space").
In all the above programmes which you and Tony has mentioned,
object reference is not loss.
consider the following code in which object "Hello" becomes a candidate for garbage collection.
class gc{
public static void main(String args[]){
String str1 = new String("Hello");
String str2 = "Bye";
str1 = str2; // After the execution of this statement
} // str1 will lost the reference of Hello
} // and Hello will be available for GC.
Hope this help..
Regards,
Hassan Naqvi.
Consider Paul's rocket mass heater. |