[hibernate-dev] Memory consumption

Andrej Golovnin golovnin at gmx.net
Tue May 15 17:51:38 EDT 2012

Hi all,

finally I have found the cause of this problem.

But before I describe what caused it, I would like to make two suggestions:

1. Consider avoiding usage of String#toLowerCase() and String#toUpperCase()
    without specifying a Locale. Users running Hibernate on systems with Turkish as default
    locale may see unexpected results. In Turkish there are two lowercase letters 
    \u0069 ‘i’ and \u0131 ‘ı’ (dotless ‘I’). And they are totally unrelated. Their uppercase
    versions are \u0130 ‘İ’ (capital letter ‘I’ with dot above it) and \u0049 ‘I’.
    So if you convert \u0049 ‘I’ to lower case and the system uses Turkish as default
    locale, you will get \u0131 ‘ı’ (dotless ‘I’) and not 'i', e.g. 'MY_COLUMN_I' would be converted
    to 'my_column_ı' and not 'my_column_i'. If you run Hibernate tests with Turkish as default locale
    some tests fail. I have for now no idea, what locale should be used instead of the default
    one. :-(

2. Do not use HashMap#clone(). If the JVM is started with the option
    -XX:+AggressiveOpts, the HashMap#clone() may produce memory leaks.
    See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7042126.
    IMHO the copy-constructor should be as fast as #clone().

Now to the memory consumption problem. The problem was introduced with the fix
of https://hibernate.onjira.com/browse/HHH-4546. Additional LockModes lead
to increased memory consumption. When I comment the changes made by 
HHH-4546 in the method AbstractEntityPersister#createLoaders() out, I get nearly
the same size for SessionFactoryImpl as it was in Hibernate 3.2.7
(see http://goo.gl/UB47c).

I have created a small patch to solve/avoid this problem. It creates loaders lazily for some
of LockModes (see http://goo.gl/wUn4w). With this changes the memory consumption
of SessionFactoryImpl right after server startup drops from ca. 370MB to
ca. 132MB (see http://goo.gl/GQw3p).

What do you think about this changes?
Btw it passes all tests. :-)

One more thing: Could we have a property similar to "hibernate.listeners.envers.autoRegister"
for Validator? I would like to disable Validator completely as it produces too much garbage
(look at the pictures) when the application is deployed. 

Best regards
Andrej Golovnin

More information about the hibernate-dev mailing list