MorphiaOrg / MorphiaOrg/morphia
Possible memory leak when starting session with lazy @Reference entity
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 449
- Avg merge
- 7m
- Merged PRs (30d)
- 10
Description
Duplicate of #3513 for milestone 3.0.0
Describe the bug
Metaspace keep increasing without dropping down after repeated query with a new session.
I am not sure if this helps, but I found many $$ReferenceProxy in the heap.
To Reproduce
Steps to reproduce the behavior:
-
Create an entity with @Reference like: @Reference(lazy = true, idOnly = true, ignoreMissing = true)
-
Query the entity repeatedly like:
FindOptions options = new FindOptions();
options.sort(Sort.descending("_id"));
options.limit(1);
for (int i = 0; i < loop; i++) {
options.skip(i);
Datastore ds = getMorphiaDatastore();
List tmp = new ArrayList<>();
try(MorphiaSession s = ds.startSession()){
Query q = s.find(ClazzWithRef, options).filter();
MorphiaCursor cursor = q.iterator();
//tmp = cursor.toList();
cursor.close();
}
}
Expected behavior
Metaspace should drop after GC
** Please complete the following information: **
- Server Version: 8.0.4
- Driver Version: 5.3.1
- Morphia Version: 2.5.0
Additional context
Tested with entity with no @Reference is fine.
Tested without starting a new session is also fine.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked duplicate issue #3513 first, then run the provided Java reproduction with lazy @Reference and repeated new MorphiaSession instances. Compare memory behavior with and without @Reference and with sessions disabled; done means identifying and preventing the retained $$ReferenceProxy/metaspace growth while preserving the reported query behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mongodb
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100