jvmvisualvmheap-dump

How is it possible for an object not being referenced by other objects in Java heap dump?


I opened a heap dump in VisualVM and some objects don't have incoming references to them. They are unreachable.

I wonder: is it OK to see them? Are they subject to a next GC and just slipped into the heap dump?

The full GC usually has 10-20 minutes intervals. Soft/Weak references are not the case.


Solution

  • jmap has an option to control that controls should a dump contains unreachable objects:

    -dump:[live,]format=b,file=<filename>
    

    Dumps the Java heap in hprof binary format to filename. The live suboption is optional. If specified, only the live objects in the heap are dumped. To browse the heap dump, you can use jhat (Java Heap Analysis Tool) to read the generated file.

    This indirectly tells that a heap dump could contain unreachable objects.

    jcmd syntax is:

    jcmd $PID GC.heap_dump -all -overwrite -gz $FILE.hprof.gz
    

    The flag -all adds dead objects, by default only live. Unlike for jhat where all are by default.

    Seems TLAB (Thread Local Allocation Buffers) has nothing to to with a heap dump, it is only a special per thread area for a young generation.