There seems to be a memory leak when JPA repository findBy... method accepts Pageable argument. If I remove Pageable from repository method signature, there is no leak.
Attached simple reproducible project that run repository query method in infinite cycle on ApplicationStartedEvent. If I run it with low heap limit (like 50-100mb) I get OutOfMemoryError in few seconds.
Tried with H2 and PostgreSQL databases, both cases have memory leaks.
Might also be related to Hibernate somehow, but I am not sure how to track it down to hibernate code.
Also screenshots from VisualVM attached, that shows Spring Data JPA related objects are in top.
This is related to DATAJPA-1575 which introduced caching fo rparameter data. Unfortunatly it uses a class without proper equals and hasCode (ParameterMetadata)implementation as a map key
We introduced the cache to avoid recomputation as createCriteriaBinder heavily create new collections. Shouldn't the fix rather be implementing proper equals and hashCode methods Jens Schauder?
I didn't do anything in this directions for two reasons:
the memoization never worked as far as I could tell, so I wasn't not at all sure that it is actually beneficial/significant.
ParameterMetadata has indirectly a reference to the EntityManager
I think it was via the ParameterExpression.
Therefore it can't be easily memoized by just adding an equals and hashCode implementation.
I vote for having a separate issue for implementing proper memoization if it is worthwhile
Oleg Kolychev opened DATAJPA-1647 and commented
There seems to be a memory leak when JPA repository findBy... method accepts Pageable argument. If I remove Pageable from repository method signature, there is no leak.
Attached simple reproducible project that run repository query method in infinite cycle on ApplicationStartedEvent. If I run it with low heap limit (like 50-100mb) I get OutOfMemoryError in few seconds.
Tried with H2 and PostgreSQL databases, both cases have memory leaks.
Might also be related to Hibernate somehow, but I am not sure how to track it down to hibernate code.
Also screenshots from VisualVM attached, that shows Spring Data JPA related objects are in top.
Affects: 2.2.3 (Moore SR3)
Attachments:
Issue Links:
Referenced from: pull request #402, and commits 0b70952, 3476a21, 25ebe74, 88b942b
Backported to: 2.2.4 (Moore SR4)
The text was updated successfully, but these errors were encountered: