title: what are "live" objects in java heap? (heap dump with jmap)
body: <p><strong>jmap</strong> help shows:</p>
  
  <p>...</p>
  
  <blockquote>
  <pre><code>-dump:&lt;dump-options&gt; to dump java heap in hprof binary format
                      dump-options:
                        live         dump only live objects; if not specified,
                                     all objects in the heap are dumped.
  </code></pre>
    
    <p>...</p>
  </blockquote>
  
  <p>Once I dump a Tomcat (with java param -Xmx384m) heap:</p>
  
  <pre><code>jmap -dump:file=dump.bin &lt;pid&gt;
  </code></pre>
  
  <p>I got a dump file of ~300M.</p>
  
  <p>When I dump its heap with <em>live</em> objects only:</p>
  
  <pre><code>jmap -dump:live,file=live-dump.bin &lt;pid&gt;
  </code></pre>
  
  <p>I got a dump file of ~120M.</p>
  
  <p>My guess of <em>live</em> objects may be:</p>
  
  <ol>
  <li><p>Objects in young generation;</p></li>
  <li><p>Objects that are used / referenced / reachable and will not be collected.</p></li>
  </ol>
  
  <p>Which one is right?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My guess #2 seems correct, and thanks for Alexey Ragozin's explanation (<code>live</code> option will cause a full GC). I tested again according to his hint:</p>
  
  <pre><code>jmap -dump:file=dump.hprof &lt;pid&gt;
  jmap -dump:live,file=live-dump.hprof &lt;pid&gt;
  jmap -dump:file=after-live-dump.hprof &lt;pid&gt;
  </code></pre>
  
  <p>size of these 3 files are:</p>
  
  <pre><code>dump.hprof ~190MB
  live-dump.hprof ~40MB
  after-live-dump.hprof ~40MB
  </code></pre>
  
  <p>so after <code>-dump:live</code>, almost all objects in heap are live.</p>