Potential memory leak

#1

In a certain use case in our client application, we noticed a memory leak. I've attached a minimal test project, that demonstrates this behavior.

Testcase description:
The test consists of one simple entity class (Person) and one embeddable class (AuditData), which is referenced by the entity. The Main class opens a database file, creates an EntityManagerFactory and interacts with the Metamodel. If that is executed multiple times (therefore there's the for loop in Main), I notice an increasing heap usage and also the number of threads increases. With each iteration, two new ODB-FileWriter threads seem to be created - one for the entity, one for the embeddable.

The usecase may be a bit unusual - the background is, that our client allows the user to store data for offline usage, which can later by synchronized with the server database. A user can create and delete the local ObjectDB file (and repeat the steps as often as they like).

#2

ObjectDB uses an EntityManager to access the metamodel and in this specific case, as there is no EntityManager, ObjectDB creates a dummy one that may not be released properly. We will work to fix it. As a workaround, try accessing the metamodel from an EntityManager or at least from an EntityManagerFactory that has at least one EntityManager.

ObjectDB Support
#3

Thank you very much. Changed the code as per your suggestion - looks good both in the testcase and in our real application.

Reply