OutOfMemoryError: memory leak in QueryInterpretationCacheStandardImpl
Description
Attachments
Activity

John Gee March 18, 2025 at 2:06 AM
In our case, we found a pattern today that most of the queries being retained were created by some deprecated routines, setResultTransformer
and AliasToBeanResultTransformer
. e.g.
I see 47k queries retained in heap dump using Eclipse MAT with OQL query:
Using “Merge Shortest Paths to GC Roots” on a heavily repeated entry shows a chain with eviction
in the path, so thrashing the cache might be triggering a problem with the eviction code (or the deprecated code is entirely to blame!).
We are refactoring code to get rid of the deprecated routines and hoping we have solved the memory leak…

John Gee March 17, 2025 at 3:05 AM
We upgraded from Hibernate 5.6.15.Final to 6.6.6.Final and experiencing similar symptoms. We eventually get CPU and GC meltdown rather than a hard OOM. Using G1GC. Large amounts of retained heap showing against queryPlanCache in Eclipse MAT analysis of a heap dump.
We have been trying to find a setting to change. We have not explicitly turned on the cache, but maybe we should! (Running out of ideas.)
Yesterday we added these settings, but still seeing memory climbing:
Next we are going to try an explicit cache purge from code to see if it has any affect: (sessionFactory.getCache().getQueryPlanCache().clear()), and downgrading
And separately, preparing a downgrade to Hibernate 6.2 based on original post here.
Bug was introduced in 6.3.0.
Checked versions 6.2.32, 6.3.0, 6.6.7. Currently we use 6.2 branch in our project, I checked all available versions for upgrade. And starting from 6.3.0 there is a memory leak that prevents us from the upgrade, even in latest version (6.6.7)
Here is graph for memory usage. App ran for 4.5 minutes, and went from 74 mb to 126 mb. On old version we had the same memory usage, it wasn’t changing over time
Increased memory usage is related to field
queryPlanCache
inQueryInterpretationCacheStandardImpl
class. On older version it was around 20 kb, now it grows over time, and it grew to 34.5 mb in several minutes. With time it goes even higher, and app crashes with OOMAs I see the cause of the error is the following. Before 6.3, this code wasn’t executed at all (tried to set break point at
queryPlanCache.put
line):In our case, there are two callers. Two daemons who periodically try to fetch data from db. Both queries are simple
CriteriaQuery
, with 1-2 static conditions.Affected code was refactored in