We also know that the an object becomes eligible for garbage collection when there are no more reachable references to it. Obviously, if there are no reachable references, it doesn\'t matter what happens to the object. We have a some code which is xplain something which is useful for us:
public class GarbageTruck {
public static void main(String [] args) {
StringBuffer sb = new StringBuffer(\"hello\");
System.out.println(sb);
// The StringBuffer object is not eligible for collection
sb = null;
// Now the StringBuffer object is eligible for collection
}
}
In this code StringBuffer which is an object , which have a value Helo , thats assigns reference variable sb in the third line.Even rest of code doesn\'t use the StringBuffer .Its not imp for the garbage collection.
By:umang
Date:2014-03-09 00:00:00
Overriding hashCode() and equals()
What It Means if we Don\'t Override equals()
Implementing an equals() Method
So What Do we Do with a Collection?
Key Interfaces and Classes of the Collections Framework
Overview of Memory Management and Garbage Collection
Overview of Java\'s Garbage Collector
When Does the Garbage Collector Run?
How Does the Garbage Collector Work?
Reassigning a Reference Variable