After a QueryPlanCache.cleanup() the cache still retains a lot of memory (~500MB), but it should be empty.
I empty the cache using the *entityManager *as follows:
After the cleanup I did a heapdump and notices that the segments tables were cleared but the evictions LIRS header was not, causing the memory leak issue.
From the LIRS source code, only the accessQueue is cleared:
org\hibernate\internal\util\collections\BoundedConcurrentHashMap.java (line 1096):
Heapdump screenshot in Eclipse MAT:
Java 1.8.0_162, JVM: Java HotSpot(TM) 64-Bit Server VM (25.162-b12, mixed mode), Windows 10, Postgres 10