When a method completes, all the local object defined in the method become eligible for garbage collection. In case an exception occurs when does the local object become eligible for garbage collection.
If the Exception comes to JVM then garbage collector will not run because when the exception comes to jvm, it will terminate the current program and remove all the stuff from the heap.so,it does not matter whether the objects are eligible or not.
and if the exception is caught by some catch statement or in other method,then it will not affect anything because every object is on the heap and nothing is removed due to this.
Exception occurs just because of the code which jvm can't execute.so, it wouldn't affect the objects created in the heap.
I don't understand the question. When an object becomes out of scope, it becomes eligible for GC. What has that to do with exceptions?? Even if you catch the exception, and the reference variable was declared inside the try block, that variable will be out of scope and thus the object it references will be eligible for GC...
Ankit has made a good point.
An Object is a candidate for GC when it's unreachable, or not accessible by a live thread.
So, it shouldn't differ in case of Exceptions.
But JVM might have a different way to unallocating memory in case of Exception - in order to improve performance.