NagarajGoud uppala wrote:
from the above discussion my understanding is, when we call the gc() it will remove the
objects which are not reffered by any reference variable and the objects
having the null value.
am i right???
Well it is not true. A call to gc() is just a request to the JVM to run the garbage collector. It is not sure if any objects will be garbage collected. This is why questions containing explicit call to gc() have been removed from
SCJP 6.
The only thing that is sure about garbage collector is that it will run once before throwing an OutOfMemoryException. Other than that, you can't say when the garbage collector will run. In the exam, you'll only get questions asking how many objects are ELIGIBLE for garbage collection. No one will ask you how many objects are garbage collected as it cannot be determined...