PDA

View Full Version : Hibernate Memory Leak: @Cache and HashtableCacheProvider don't mix


kjkoster
13-12-2008, 20:48
Dear All,

I have just found and fixed a problem with a Hibernate that I thought I should share.

I had configured an application server with Hibernate to use Ehcache (http://ehcache.sourceforge.net/) as its second level cache. To enable caching I had annotated each entity class with the appropriate @Cache annotation (http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#d0e2911). That worked fine, until I decided to remove Ehcache. My application started leaking memory like carrying tea in a sieve.

As it turned out, I had left the @Cache annotations in. Apparantly the HashtableCacheProvider (http://www.hibernate.org/hib_docs/reference/en/html/performance-cache.html) does not release objects at all. Not even after a while. I guess that answers my question why using HashtableCacheProvider in production is bad. :-)

At any rate, I removed the annotations and now everything is back to normal.

Kees Jan

PS. Why remove Ehcache? I had to move to a new version of Ehcache and that brought in so many extra dependencies that I decided to cull it. I didn't want a fourth complete logging framework (http://www.slf4j.org/). Too much bloat. Plus, it makes no noticeable difference in performance anyway. It is not even worth the bloat.

Tobias
22-01-2009, 17:10
Please note that you can configure TreeCache (from JBossCache) to work in a "LOCAL" mode without any replication. I guess the other features like limits and timeouts are still available then.

kjkoster
25-01-2009, 14:44
Dear Tobias,

Thank you for the advise. I'll be working with JBoss cache in my current client project. If I need the extra caching it might just make it into Java-monitor. :-)

At the moment I have other issues to worry about, such as the high number of false positives and the fact that we go down hard when there is even a small ISP issue.

Kees Jan