Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JpaRepository memory leak with Pageable argument [DATAJPA-1647] #1951

Closed
spring-projects-issues opened this issue Dec 15, 2019 · 4 comments
Closed
Assignees
Labels
in: core Issues in core support type: bug A general bug

Comments

@spring-projects-issues
Copy link

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:

  • DATAJPA-1575 Performance improvements in repository invocation handling

Referenced from: pull request #402, and commits 0b70952, 3476a21, 25ebe74, 88b942b

Backported to: 2.2.4 (Moore SR4)

@spring-projects-issues
Copy link
Author

Jens Schauder commented

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

@spring-projects-issues
Copy link
Author

Mark Paluch commented

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?

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Maybe.

I didn't do anything in this directions for two reasons:

  1. the memoization never worked as far as I could tell, so I wasn't not at all sure that it is actually beneficial/significant.
  2. 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

@spring-projects-issues
Copy link
Author

Mark Paluch commented

Good point. I didn't catch the reference to EntityManager in the first place. I'll move forward with merging the PR. Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants