Impossible Java memory references in the dump heap

I have a Java heap dump done at 7:41 p.m. which I am analyzing using the Eclipse memory analysis tool. The heap dump includes 20 session objects.

Using the GC Roots Path command on one of these session objects in my heap shows the following 3 links to the session object.

  • Link to the finalizer from the "incomplete" linked list belonging to the Finalizer stream. My goal is the 3rd line to be completed.
  • A strong reference to the session object from the message handler thread, which itself refers to the TimerTask cleanup scheduled to run at 19:11.
  • Weak reference to the session object from the WeakHashMap $ entry. WeakHashMap is supported by a live static link.

How can a session object be in the finalizer queue when it still has a strong and weak link?

Of the remaining 19 objects of the session, another 1 is in the finalizer queue and has a similar weak link. All other 18 session objects are weakly referenced. Why hasn't GC cleared these weak links?

A few general points:

  • Objects are only eligible for finalization AFTER their weak links have been cleared (http://download.oracle.com/javase/6/docs/api/java/lang/ref/package-summary.html)
  • The session object does not have a finalizer that could resurrect it, and even if it had not been executed, it could not be started while the object is still in the incomplete queue for other objects.
  • My application does not use Phantom refs, which are the only links that should be available as soon as the object is eligible for finalization. Even if my application did use Phantom refs, these objects do not display their reference to the object they store.
+4
source share
3 answers

I think the error you make here is in this part:

Link to the finalizer from the "incomplete" linked list belonging to the Finalizer stream. My object takes 3rd place in the queue.

If you talk about it:

static private Finalizer unfinalized = null; 

in Sun Finalizer.java (a Finalizer contains a next and prev Finalizer , therefore, part of the β€œlinked list” for those who play at home), then this is not a list of things to be completed.

Finalizer.add() not (as I think you assume) called during the finalization process when the object is unavailable; rather, this method is called during object creation (for example, during <init> , using native code for any object that overrides finalize() .

The presence of Finalizer in the next chain does not mean that it should be completed; this is

 static private ReferenceQueue queue 

which contains such objects. Being in a linked list means that it has a finalize() method.

Therefore, your first point is a red herring, your second point, which keeps the element accessible, and the third point flows from the second (because WeakReference will not be cleared until the object is reached).

Hope this helps!

+10
source

Weak links are just a sign for the GC. You have no serious guarantees when it will be cleaned.

0
source

You can again make the object planned for finalization.

I know about:

A session object does not have a finalizer that could resurrect it and even if it did so it could not be started while the object is still in the unfinished queue for other objects.

However, there may be other objects that do this (i.e., turning to the session and getting yourself rez'd). In any case, show the finalizer of this session.

Notes: before clearing phantom refs, the object will NOT be available for completion. (Phantom links are most often used to plan pre-mortem cleanup actions, javadoc), pre (not post like Weak).

0
source

Source: https://habr.com/ru/post/1335399/


All Articles