1

This is possibly a naive question. I am in the process of investigating a probable memory leak in my application. I've been monitoring the tomcat process via jvisualvm. At one point I opted to do a heap dump.

I was surprised to see my thread count, and memory consumption drop considerably after the heap dump was generated. Reference the following screen shots.

Threads Memory

Why did my thread count and memory drop just because of a heap dump?

[EDIT] In response to the answers about it doing a full garbage collection in response to the heap dump, my followup question would be, shouldn't garbage collection be happening all the time? I see no prior dramatic drops, just the regular ones that occur when GC happens normally. What is different with this GC cycle than what happens normally?

Bill
  • 2,623
  • 1
  • 27
  • 41
  • 1
    In general full GC will be triggered before performing heap dump, that might be causing thread count drop. – kosa Aug 01 '13 at 18:25
  • I love when the top result of a related google search is the SO question being duplicated. – Tim Bender Aug 01 '13 at 18:28

3 Answers3

2

Before the dump, your program was in a steady state consisting of:

  1. allocating short-lived objects;
  2. a minor GC occurring, clearing them all out.

At the same time, there were quite a lot of unreachable objects hanging around, which belonged to the tenured generation.

Then you made the thread dump. This operation by itself consumes a lot of memory, and as a result a major collection happened. This wiped out your tenured objects.

Now, these objects may have had finalizers run, or they may have been related to some soft references, and in response to their collection/finalization, a number of threads ended.

This then caused your heap allocation slope (bytes allocated per second) to become dramatically flatter.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
1

A heap dump may trigger a full Garbage Collect prior to writing out the heap.

Tim Bender
  • 20,112
  • 2
  • 49
  • 58
1

When you trigger a heap dump, you are also triggering a full collection. Some of your daemon threads could be stopped when a resource without a strong reference disappears.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130