<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd" >
<reference id="ref_inspections_path_to_gc_roots" xml:lang="en-us">
<shortdesc>Find out more about objects that could or should be garbage collected.
Copyright (c) 2008, 2018 SAP AG, IBM Corporation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
<p>Sometimes a heap dump contains objects which would be removed at the next garbage collection.
These are objects which are unreachable from the garbage collection roots.
By default, Memory Analyzer removes these objects as part of the parse process as normally they are not
important in determining a memory leak. If the heap dump is generated as a result of an <apiname>OutOfMemoryError</apiname>
then the Java virtual machine will usually have performed a garbage collection operation to attempt to
free space for the new object, so there will not be those objects in the heap dump file.
There is a chance that the garbage collection was not performed, for example if the
object to be allocated was so huge that it was obvious to the JVM that no amount of garbage collection
could free enough space, or if the heap dump was triggered by another event.</p>
<p>Sometimes however, it is interesting to investigate these unreachable objects. For example if the application
is spending a lot of time garbage collecting then it may be allocating and discarding more objects
than is sensible. The types of the objects which could be discarded at the next garbage collection
gives a clue as to which temporary objects the application is causing to be allocated.
When acquiring a heap dump for this purpose using the Memory Analyzer,
do not use the <cmdname>live=true</cmdname> option as that would discard unreachable objects
before the heap dump is generated.</p>
<p>Invoke using either:
<li>From the link on the Overview page
<li>From the Query Browser via <menucascade><uicontrol>Java Basics</uicontrol><uicontrol> Unreachable Objects Histogram</uicontrol></menucascade></li></ol>
The result is a histogram table showing the class names and number of object instances
of the unreachable objects, together with their total sizes.
This histogram has no object graph behind it (unreachable objects are removed during the parsing of the heap dump,
only class names are stored).
Thus it is not possible to see e.g. a list of references for a particular unreachable object.
<alt>Table displaying the unreachable objects.</alt>
<p>If more information about the unreachable objects is required then the following steps
can include the objects in the snapshot.</p>
<li>Close the snapshot
<li>Select the heap dump using <menucascade><uicontrol>Window</uicontrol><uicontrol>Heap Dump History</uicontrol></menucascade>
right-click, <menucascade><uicontrol>Delete Index Files</uicontrol></menucascade>
<li>Select 'Keep unreachable objects' using <menucascade><uicontrol>Window</uicontrol><uicontrol>Preferences</uicontrol>
<li>Reopen the heap dump, which will reparse the heap dump.</li>
<li>Select the <menucascade><uicontrol>Java Basics</uicontrol><uicontrol>GC Roots</uicontrol></menucascade>
<li>Select the 'Unreachable Objects' row.</li>
<li>Run the 'Show Retained Set' query on that row.</li>
This will show a histogram of all the objects which normally would be unreachable and would be garbage collected
at the next opportunity. As these objects are now in the snapshot they then can be inspected in more detail.
<link href="../../concepts/reachability.dita" />
<link href="../../concepts/gcroots.dita" />
<link href="../../tasks/configure_mat.dita" />
<link href="../../tasks/acquiringheapdump.dita" />
<link href="../../reference/inspections/retained_set.dita" />