I'm currently trying to figure out where a big memory leak is hiding. I
press a button and 1 out of 3 times my memory increases by 20MB, even
though is should not increase at all.
It would be a great help in this situation to be able to take a hprof file
before and one after, and get a list of classes that were added. A diff so
to speak. Then at least I could see what causes the 20MB and give me a
good starting point. Now it's educated guessing and poking.
well we already offer such a diff, although we want to improve this
functionality.
When you open the histogram view of a heapdump, try the rightmost icon in
the icon bar (compare to another heapdump). You can compare two heapdumps,
which should be already be opened. Since the compare functionality works
on the histogram (aggregating objects on class level), it should be almost
what you desire.
Let me explain: The heap dump identifies objects by its object address.
But this object address is not stable. Whenever the Garbage Collector
moves an object (within the eden spaces, into the old generation, etc.),
the object is assigned a new object address. Therefore it is not possible
to say whether an object was just moved or whether one instance was
garbage collected and another one created.
Hence, the Memory Analyzer compares heap dumps on an aggregate level. This
is the histogram (objects group by classes) or the class loader histogram
(objects grouped by the name of the class loader).
BTW, profiling tools overcome this limitation by assigning unique object
ids during the profiling run. This, of course, is an overhead which might
be perfectly acceptable for debugging, but is usually not done in
production systems.
Being able to do diffs between snapshots is a great feature, but it's
hidden too well.
The "Basic Analysis" section of the welcome screen says:
"To compare two snapshots open a baseline snapshot and a later snapshot
and press the Show differences toolbar button, and select the baseline
snapshot to see the differences."
The only way I finally figured out that I had to open the histogram first
is from this topic. That detail needs to be added to the text.
I had exactly the same confusion as John encountered. It was only when I did a search and found this thread that I located the icon. Currently the welcome text reads:
"To compare two snapshots open a baseline snapshot and a later snapshot and press the Show differences toolbar button, and select the baseline snapshot to see the differences."
Would be great if you could improve this to avoid confusion for future users. Thanks!
To compare two snapshots open a baseline snapshot and a later snapshot and from the snapshot Class Histogram view press the
Compare to another Heap Dump
toolbar button, and select the baseline snapshot to see the differences. There is also a more general comparison view using the compare basket. Tables and trees are added to the compare basket from the Navigation History.
There isn't time at the moment to update the tutorials further.