Hi I have one doubt about phantom reference. What I understand the finalize method is called just before when object are going for garbage collection. But some time if object are not eligible for garbage collection then finalize method will not execute.
Now talking about phantom reference when this finalize method will called.
Is finalize always called in phantom reference.
I am very much confuse about this. Please help me.
When object becomes available only through phantom reference then after the first GC
finalize()
method is invoked and after the second GC the reference is enqueued. If after that phantom reference is cleaned (or becomes unavailable itself) then the memory is cleared after the third GC.