Nulling a Reference

Nulling a Reference

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\");
 // 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.

Date:2014-03-09 00:00:00

Post Your Answers

User Email:

User Name:

Related scjp1.5 chap8 Links

scjp1.5 chap8 interview questions and answers for experienced and fresher