There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
All the objects created inside a method are eligible for garbage collection
once method completes. If method passes reference to any object created inside the method to the outside world is an exception to this fact.
cmbhatt
Eisa says,
public static void main(String [] args) {
String s=new String("EW");
String s2=new String("AS");
go(s,s2);
}
static void go(String s1,String s2){
s1=null;
s2=null;
}
is s,s2 is eligible since its pass by reference ?
Note: If using that reference variable, you do internal modification on the
object, it will have global impact, because object is same. But if the called method make reference variable "null", it means it is losing the reference of the object on the heap. Calling method reference variable wont have any effect of that. It's reference variable still points to the object on the heap.
cmbhatt
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
cmbhatt
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |