Java Reference
In-Depth Information
Figure 7-10. Finalizer references retain more memory
When the reference queue processes the finalizer, the Finalizer object (as usual) will be re-
moved from the queue and then eligible for collection. Only then will the referent also be
freed. This is why finalizers have a much greater performance effect on GC than other indef-
inite references—the memory consumed by the referent can be much more significant than
the memory consumed by the indefinite reference object.
This leads to the functional problem with finalizers, which is that the finalize() method
can inadvertently create a new strong reference to the referent. That again causes a GC per-
formance penalty: now the referent won't be freed until it is no longer strongly referenced
again. And functionally it creates a big problem, because the next time the referent is eligible
to be collected, its finalize() method won't be called, and the expected cleanup of the ref-
Search WWH ::

Custom Search