When you are confronted with a memory issue, there are certain tools you can use to analyze the memory usage.

One such tool, when using an IBM JVM, is the IBM Heap Analyzer.

This tool is described on this page:

On this page, you can find a link to the latest ha*.jar, as well as a webcast (audio and slides separately) about the original tool.

Here is an example of the steps one can take to analyze a problem. The problem in this example is DERBY-6096. These are the steps:

33,729,032 bytes (53.69 %) of Java heap is used by 1,000 instances of org/apache/derby/impl/services/cache/ClockPolicy$Holder

27,039,776 bytes (43.04 %) of Java heap is used by 842 instances of java/util/HashMap$Entry

In the case of DERBY-6096 the problem was that BLOB size was estimated at 0, and thus the memory usage needed by BLOBs was estimated as small, leading Derby to try to hold large objects in memory when trying to do a hash join