| Author |
Refference variables and garbage collection
|
Gjorgi Var
Ranch Hand
Joined: Feb 24, 2004
Posts: 85
|
|
Hi, If we have two refference variables that are assigned to each other, both will reffer to the same object on the heap. But if we assign one of them to null after we have assigned it to the other variable, wll that object be subjected to garbage collection? Why would it be or would be not?
|
 |
Tom Henner
Greenhorn
Joined: Jul 04, 2005
Posts: 18
|
|
|
Java passes a copy of the reference value. So setting a to null does not change the reference that b already has. Your object is safe from the gc.
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
No, the object is not available for garbage collection until there are NO MORE references to it. This is a very key concept since it is easy to forget to null out all references when you are finished with an object. Layne
|
Java API Documentation
The Java Tutorial
|
 |
 |
|
|
subject: Refference variables and garbage collection
|
|
|