I have a Java Heap Dump taken at 7:41pm which I am analysing with Eclipse Memory Analysis Tool. The heap dump includes 20 session objects.
Using the Path to GC Roots command on one of these session objects in my heap shows the following 3 references to the session object.
How can the session object be on the finalizer queue when it still has a strong and a weak reference?
Of the remaining 19 session objects, 1 more is in the finalizer queue and has a similar weak reference. All the other 18 session objects are only weakly referenced. Why hasn't the GC cleared these weak refs?
A few general points:
I think the mistake you're making here is in this part:
A finalizer reference from the "unfinalized" linked list owned by the Finalizer thread. My object is 3rd in line to be finalized.
If you're talking about this:
static private Finalizer unfinalized = null;
in Sun's Finalizer.java
(a Finalizer
contains a next
and prev
Finalizer
, hence the 'linked list' part, for those playing along at home), then that's not the list of things to be finalized.
Finalizer.add()
is not (as I think you're assuming) called during the finalization process, when the object is unreachable; rather, that method is called at creation time of the Object (e.g. during <init>
, by native code, for any Object which overrides finalize()
.
The presence of a Finalizer in the next
chain doesn't mean it's about to be finalized; it's the
static private ReferenceQueue queue
which holds such objects. Being in the linked list just means that it has a finalize()
method.
Therefore your first point is a red herring, it's your second point that's keeping the item reachable, and the third point flows from the second (because the WeakReference
won't be cleared while the object is reachable).
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With