In the above code does exception objects will be garbage collected??
Hello Hareendra I want to give you my understanding of the above code.
1. An object is eligible for garbage collection when NO LIVE threads can access it. And that means NOT having a REACHABLE reference variable that refers to the object.
2. According to the execution of the above program, an exception is thrown in line 5 that is caught in line 6 and runs the codes in line 7 and 9 respectively.
3. nfe AND i are REACHABLE reference variables -(I THINK SO)- which means the objects they refer to CANNOT be garbage collected.
4. s does NOT refer to any object.
5. The answer to your question is NO the exception object that nfe refers to will NOT be garbage collected.
PLEASE take note that I am studying java just like you, I might have made a mistake in my explanation or not.
Thats up to the experts that mediate in this forum to look out for, I hope you find my analysis usefull thanks.
In Your Pursuit Towards Certification, NEVER Give Up.
I want to appreciate you that you are very clear and nice way to explain also
and don't hesitate to ask even the questions which you seem silly
no question is silly at all
@Harindra, objects eligible for garabage collection cannot be determined here according to me
as this method testing will be called by passing some value
and if that value is referred by a variable, then s= null in this method won't make it eligible for garbage collection
for that, it will be good if complete code is provided