[hibernate-dev] Memory consumption

Andrej Golovnin golovnin at gmx.net
Thu May 10 18:11:03 EDT 2012

Hi all,

we use a EAR file which contains a WAR file and a JAR file with
all our entity classes.  And we have a single persistent unit.
We don't use JavaBean validation, nor we use Hibernate Envers.

Here is a small list with numbers for our application(not sure
if it would help to understand/solve the problem):

Used Access type: FIELD
Number of tables: 1299
Number of columns: 18045
Number of classes with @MappedSuperclass: 45
Number of classes with @Entity (including abstract classes): 970
Number of classes with @Embeddable: 233
Number of classes with @Inheritance: 13

The screen shot with JBoss 4 is made from memory snapshot
of a running production system. The screen shot with JBoss 7 is made
from memory snapshot right after startup (no application code were executed,
Lucene indexes are empty).

About "nearly twice as much memory":
The situation is following. When I start JBoss 4 with our application
and look at the memory consumption, I see that ca. 300MB of heap
are already allocated. The most memory is consumed by objects
related to the "org.hibernate"-package and by objects related
to JPA support from the "org.jboss"-package. When I start JBoss 7
with our application, I see now more than 600MB of the used heap.
And the most memory is again consumed by objects related to

After updating JBoss 7 to use the Hibernate Validator 4.3.0 and
adding <property name="javax.persistence.validation.mode" value="NONE"/>
to our persistence.xml file I was able to reduce memory consumption
of SerializableValidatorFactory from ca. 90MB to ca. 256KB. :-)
What I was not able to do, is to avoid loading of Hibernate Validator
and Hibernate Envers at all as we don't use them.

It's also unclear to me why Configuration, JavaReflectionManager,
FullTextIndexEventListener don't show up. If I use MAT, I see that
the size of JavaReflectionManager is nearly identical in both cases.

I need more time to investigate the differences between the old and
new versions. But one thing you can change already:
Configuration#seconPasses should be recreated
when Configuration#secondPassCompile() finishes or consider using
LinkedList. In my case the #seconPasses has the size of 0. But the backend
array has the length of ca. 27000. With this change you will not save a lot of
memory, but I welcome every single byte I can get. :-)

Best regards
Andrej Golovnin

More information about the hibernate-dev mailing list